Skip to content
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

Merged
merged 5 commits into from
May 16, 2020
Merged

add some unit tests #8960

merged 5 commits into from
May 16, 2020

Conversation

zhouhao3
Copy link
Contributor

Signed-off-by: Zhou Hao zhouhao@cn.fujitsu.com

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 23, 2020
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 23, 2020
@zhouhao3
Copy link
Contributor Author

/assign @granular-ryanbonham

@hakman
Copy link
Member

hakman commented Apr 23, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 23, 2020
@zhouhao3 zhouhao3 force-pushed the add-ut branch 2 times, most recently from d9baa8f to 0e9af4a Compare April 23, 2020 07:04
@zhouhao3
Copy link
Contributor Author

@olemarkus PTAL

},
{
s: "~/test",
expected: homedir.HomeDir() + "/test",
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Member

@geojaz geojaz left a 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) {
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

@@ -0,0 +1,40 @@
/*
Copyright 2019 The Kubernetes Authors.
Copy link
Member

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",
Copy link
Member

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.

expected string
}{
{
s: "test",
Copy link
Member

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 :)

Copy link
Contributor Author

@zhouhao3 zhouhao3 May 12, 2020

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.

Zhou Hao added 2 commits May 12, 2020 15:55
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
},
{
role: "Node2",
expected: -1,
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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 <zhouhao@cn.fujitsu.com>
@zhouhao3 zhouhao3 force-pushed the add-ut branch 2 times, most recently from 51f8d6c to cef2975 Compare May 12, 2020 09:07
Zhou Hao added 2 commits May 12, 2020 17:26
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
Copy link
Member

@geojaz geojaz left a 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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 16, 2020
@k8s-ci-robot k8s-ci-robot merged commit 66b5322 into kubernetes:master May 16, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants