Skip to content

🍀 Proposal: pkg/util/md5 Enhancement (sub task of pkg/util Enhancement #833) - #856

Merged
xavier-hou merged 1 commit into
devstream-io:mainfrom
jxs1211:feat-pkg-util-md5
Jul 18, 2022
Merged

xavier-hou merged 1 commit into
devstream-io:mainfrom
jxs1211:feat-pkg-util-md5

Conversation

@jxs1211

@jxs1211 jxs1211 commented Jul 15, 2022 •

Copy link
Copy Markdown

Signed-off-by: xian-jie.shen 327411586@qq.com

Pre-Checklist

Note: please complete ALL items in the following checklist.

  • I have read through the CONTRIBUTING.md documentation.
  • My code has the necessary comments and documentation (if needed).
  • I have added relevant tests

Description

Maybe there is an OOM risk in this code, so try to fix it.

Related Issues

see #833 for the details

New Behavior (screenshots if needed)

  • add an defer for closing the file:
    image

  • add a ut for the funcion:

[going@dev md5]$ go tool cover -func=coverage.out
github.com/devstream-io/devstream/pkg/util/md5/helper.go:11:    CalcFileMD5     90.0%
github.com/devstream-io/devstream/pkg/util/md5/md5.go:12:       FileMatchesMD5  75.0%
total:                                                          (statements)    83.3%

@jxs1211
jxs1211 requested a review from a team as a code owner July 15, 2022 09:57
@jxs1211 jxs1211 changed the title 🍀 Proposal: pkg/util/helm Enhancement (sub task of pkg/util Enhancement #833) 🍀 Proposal: pkg/util/md5 Enhancement (sub task of pkg/util Enhancement #833) Jul 15, 2022
@jxs1211

jxs1211 commented Jul 15, 2022

Copy link
Copy Markdown
Author

@HXCGIT the TestCase in the help_test.go maybe fail, because the case needs a test file to exist in the same directory, but don't commit the test file is more reasonable, do you have any better idea for this situation.

image

@steinliber

Copy link
Copy Markdown

@HXCGIT the TestCase in the help_test.go maybe fail, because the case needs a test file to exist in the same directory, but don't commit the test file is more reasonable, do you have any better idea for this situation.

image

You can use testing.TempDir to create temp dir in test, and then create a file in the temp dir. For more you can refer https://pkg.go.dev/testing#B.TempDir

@xavier-hou

Copy link
Copy Markdown
Member

@steinliber Great solution!
@jxs1211 By the way, I just try testing.TempDir, pls note that this returns an absolute path rather than creating a temp sub-dir in current dir.

@jxs1211

jxs1211 commented Jul 16, 2022

Copy link
Copy Markdown
Author

@HXCGIT the TestCase in the help_test.go maybe fail, because the case needs a test file to exist in the same directory, but don't commit the test file is more reasonable, do you have any better idea for this situation.
image

You can use testing.TempDir to create temp dir in test, and then create a file in the temp dir. For more you can refer https://pkg.go.dev/testing#B.TempDir

good to know that!
@steinliber @HXCGIT and thank you guys

@jxs1211
jxs1211 force-pushed the feat-pkg-util-md5 branch from e25045c to eead28a Compare July 16, 2022 07:17
@jxs1211

jxs1211 commented Jul 16, 2022 •

Copy link
Copy Markdown
Author

According to your advice, I update the code in the test case, but it seems to fail at the golang lint, I don't find any lint-related error after I've checked the updated code, and the test case has passed in my local environment.
image

@xavier-hou

Copy link
Copy Markdown
Member

@jxs1211 Pls check the error msg, you should handle the returned error.
image

Signed-off-by: xian-jie.shen <327411586@qq.com>
@jxs1211
jxs1211 force-pushed the feat-pkg-util-md5 branch from eead28a to a419c77 Compare July 16, 2022 08:46
@IronCore864

Copy link
Copy Markdown
Member

Thanks for the tests, and great work on the heated discussion about TempDir :)

@xavier-hou
xavier-hou merged commit d6875bb into devstream-io:main Jul 18, 2022
@xavier-hou

Copy link
Copy Markdown
Member

@jxs1211 Merged. Many thanks for the test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants