-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add some unit tests #8960
add some unit tests #8960
Conversation
Hi @q384566678. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @granular-ryanbonham |
/ok-to-test |
d9baa8f
to
0e9af4a
Compare
@olemarkus PTAL |
upup/pkg/fi/utils/sanitize_test.go
Outdated
}, | ||
{ | ||
s: "~/test", | ||
expected: homedir.HomeDir() + "/test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is pretty much the implementation of ExpandPath
. I would change this to a hardcoded string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the HomeDir obtained in different test environments is different, I think it is impossible to write a definite string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only relevant environment is linux. you can skip if the environment is something else. If not this test is rather meaningless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the value of homedir.HomeDir ()
in a linux environment is also different, so I will delete this test. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@q384566678 Thanks for putting this together! I'm +1 on the effort to improve our unit test coverage.
In general, I think we should make the code work harder and really exercise it. :) If you have questions, happy to clarify. thanks
"k8s.io/kops/pkg/apis/kops" | ||
) | ||
|
||
func TestDefaultInstanceGroupVolumeSize(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test feels like it creates maintenance work rather than unit testing "kops logic". That is to say, DefaultInstanceGroupVolumeSize
basically just returns different constants with a switch.
IMO, changes that would break this test are likely to be intentional changes, so my vote would be to remove volumes_test.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine.
"testing" | ||
) | ||
|
||
func TestStringSlicesEqual(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I think this is a much more useful unit test than the volumes_test.
upup/pkg/fi/utils/hash_test.go
Outdated
@@ -0,0 +1,40 @@ | |||
/* | |||
Copyright 2019 The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be bumped to 2020 now?
expectedStr string | ||
}{ | ||
{ | ||
s: "test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is also a fairly useful test... could you add some more spicy or exciting edge cases? For these relatively simple functions, I would prefer to exercise the hard cases and assume the libraries generally do what they're supposed to.
upup/pkg/fi/utils/sanitize_test.go
Outdated
expected string | ||
}{ | ||
{ | ||
s: "test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again- are there any cases that better exercise the edges than these? These ones seem very easy :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestions, I have updated the relevant tests. PTAL.
Signed-off-by: Zhou Hao <[email protected]>
Signed-off-by: Zhou Hao <[email protected]>
}, | ||
{ | ||
role: "Node2", | ||
expected: -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geojaz this particular one could perhaps have some value. I suppose we want to preserve -1
being the return value for unknown roles. The above could perhaps just test for positive integers instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to add another role, it would at least be nice to see this test failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point +1 @olemarkus
Signed-off-by: Zhou Hao <[email protected]>
51f8d6c
to
cef2975
Compare
Signed-off-by: Zhou Hao <[email protected]>
Signed-off-by: Zhou Hao <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
/lgtm
thanks @q384566678
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: geojaz, q384566678 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Zhou Hao [email protected]