-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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 unit test coverage for pkg/util/node and Remove duplicate testcases for func TestGetNodeHostIPs #110825
Conversation
Signed-off-by: zhoumingcheng <zhoumingcheng@beyondcent.com>
@zhoumingcheng: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
Hi @zhoumingcheng. 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. |
/ok-to-test |
Remove duplicate testcases for func TestGetNodeHostIPs Signed-off-by: zhoumingcheng <zhoumingcheng@beyondcent.com>
/assign @thockin |
pkg/util/node/node_test.go
Outdated
t.Error("create node error") | ||
} | ||
} | ||
result := GetNodeIP(kubeClientSet, test.nodeName) |
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.
Tell me if I am misunderstanding:
Testing through GetNodeIP()
seems to give coverage of the wait.ExponentialBackoff()
logic but ultimately calls GetNodeHostIP()
. This test doesn't actually exercise any of the retry logic, so you're moving test cases around to score coverage "points" but it's bogus coverage.
I think I'd rather see all the test cases in the GetNodeHostIPs()
(plural) test, with a subset of those in a test for GetNodeHostIP()
(singular). This function (GetNodeIP()
) seems to only be called from 2 places and I think it would be better to move this function to be internal to both. "A little copy is better than a little dep".
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 the suggestion, I did notice that GetNodeIP() ends up calling GetNodeHostIP(). My GetNodeIP() test case and TestGetNodeHostIPs() both cover GetNodeHostIP(). I wonder if it's possible to cover wait.ExponentialBackoff() over GetNodeHostIP() directly via TestGetNodeIP(). So I removed TestGetNodeHostIPs. Not sure if this is possible?
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 moves in the wrong direction. Tests should focus on the lowest level possible.
I'd set this up as a comprehensive test of GetNodeHostIPs()
- since that seems to be where the real work is happening.
Testing GetNodeIP()
(if done at all) should focus on the logic that is unique to that function, which is the backoff (which is mostly boilerplate and does not really belong in this utils lib in the first place).
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'm sorry, with all your replies to me, I'm a little bit confused about what you mean here. Do I wish I could move the tests for GetNodeIP() to the called function directory, or should the tests be concentrated at the lowest level possible. If it is the second, I will remove the test cases that are repeated with TestGetNodeHostIPs() in TestGetNodeIP(). Then TestGetNodeIP() will only focus on testing GetNodeIP(). Not sure if I misunderstood what you meant if I changed it like this. Or should I move the test of GetNodeIP() to the corresponding test function of the called function, such as pkg/util/node/node_test.go Test_detectNodeIP(). Sorry to bother you.
Don't bother to test GetNodeIP() until the lower level functions have
complete, full coverage.
…On Wed, Jul 6, 2022, 7:03 PM zhoumingcheng ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pkg/util/node/node_test.go
<#110825 (comment)>
:
> + {Type: v1.NodeExternalIP, Address: "4.3.2.1"},
+ {Type: v1.NodeExternalIP, Address: "4.3.2.2"},
+ }},
+ },
+ expect: netutils.ParseIPSloppy("a:b::c:d"),
+ },
+ }
+ for _, test := range testCases {
+ t.Run(test.name, func(t *testing.T) {
+ kubeClientSet := kubeclientfake.NewSimpleClientset()
+ if test.node != nil {
+ if _, err := kubeClientSet.CoreV1().Nodes().Create(context.Background(), test.node, metav1.CreateOptions{}); err != nil {
+ t.Error("create node error")
+ }
+ }
+ result := GetNodeIP(kubeClientSet, test.nodeName)
I'm sorry, with all your replies to me, I'm a little bit confused about
what you mean here. Do I wish I could move the tests for GetNodeIP() to the
called function directory, or should the tests be concentrated at the
lowest level possible. If it is the second, I will remove the test cases
that are repeated with TestGetNodeHostIPs() in TestGetNodeIP(). Then
TestGetNodeIP() will only focus on testing GetNodeIP(). Not sure if I
misunderstood what you meant if I changed it like this. Or should I move
the test of GetNodeIP() to the corresponding test function of the called
function, such as pkg/util/node/node_test.go Test_detectNodeIP(). Sorry to
bother you.
—
Reply to this email directly, view it on GitHub
<#110825 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKWAVASYAJFSJKLSZJI35LVSY3HFANCNFSM52BHMHRQ>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
77fe3e5
to
8dfb7af
Compare
Signed-off-by: zhoumingcheng <zhoumingcheng@beyondcent.com>
/retest |
Thanks for your suggestion, I have removed TestGetNodeIP() and removed the duplicated test cases in TestGetNodeHostIPs(). |
Thanks! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: thockin, zhoumingcheng 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 |
/sig node |
/retest |
Signed-off-by: zhoumingcheng zhoumingcheng@beyondcent.com
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Improve test coverage
Run test coverage command:
Befor:
After:
Remove duplicate testcases for func TestGetNodeHostIPs
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Thank you!
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: