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

Fix incorrect test cases to cover code that needs to be tested in TestValidateIPSet #108351

Merged
merged 1 commit into from
Mar 18, 2022

Conversation

mengjiao-liu
Copy link
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

Wrong test cases:

{ // case[3]
ipset: &IPSet{
Name: "bar",
SetType: BitmapPort,
HashFamily: ProtocolFamilyIPV6,
HashSize: 0,
MaxElem: 2048,
},
valid: false,
desc: "wrong hash size number",
},
{ // case[4]
ipset: &IPSet{
Name: "baz",
SetType: BitmapPort,
HashFamily: ProtocolFamilyIPV6,
HashSize: 1024,
MaxElem: -1,
},
valid: false,
desc: "wrong hash max elem number",
},

According to the testcases desc field, we can see that case[3] is the test wrong hash size number
case[4] is to test wrong hash max elem number
However, when building the test case, the value set by the IPSet.SetType fields is BitmapPort,
SetType: BitmapPort,

SetType: BitmapPort,

which does not conform to the description of the desc field.
And this will cause the test to jump directly to verifying the PortRange of BitmapPort. At this time, PortRange == "", so it will definitely return false,
if set.SetType == BitmapPort {
if valid := validatePortRange(set.PortRange); !valid {
return false

and the verified HashSize and MaxElem part code that needs to be tested is not tested.
// check hash size value of ipset
if set.HashSize <= 0 {
klog.Errorf("Invalid hashsize value %d, should be >0", set.HashSize)
return false
}
// check max elem value of ipset
if set.MaxElem <= 0 {
klog.Errorf("Invalid maxelem value %d, should be >0", set.MaxElem)
return false
}

When we modified the code, the test coverage increased from 85.0% to 87.2% and the code that verified the HashSize and MaxElem part code that was not covered previously was covered.

Run command:

go test -cover ./pkg/util/ipset/

Befor:

ok      k8s.io/kubernetes/pkg/util/ipset        0.919s  coverage: 85.0% of statements

After:

ok      k8s.io/kubernetes/pkg/util/ipset        (cached)        coverage: 87.2% of statements

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


/sig testing

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/testing Categorizes an issue or PR as relevant to SIG Testing. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 25, 2022
@k8s-ci-robot
Copy link
Contributor

@mengjiao-liu: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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-priority Indicates a PR lacks a `priority/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/network Categorizes an issue or PR as relevant to SIG Network. labels Feb 25, 2022
@aojea
Copy link
Member

aojea commented Feb 25, 2022

great catch
/lgtm
/approve
/assign @thockin

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 25, 2022
@mengjiao-liu
Copy link
Member Author

ping @thockin

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests pass today (these cases fail successfully).

Can you explain why this change is "more correclty incorrect" ?

Would it be too much to ask to expand the comments from // case[3] to something meaningful?

@thockin
Copy link
Member

thockin commented Mar 18, 2022

I see it's not actually validating the error message. Blech.

This could/should be refactored to return error and the test should verify the error message (strings.Contains or something).

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, mengjiao-liu, thockin

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 Mar 18, 2022
@k8s-ci-robot k8s-ci-robot merged commit 54ee338 into kubernetes:master Mar 18, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Mar 18, 2022
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. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants