-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Remove usage of assertion libraries in pkg/scheduler tests #130710
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
base: master
Are you sure you want to change the base?
Remove usage of assertion libraries in pkg/scheduler tests #130710
Conversation
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-sigs/prow repository. |
Hi @pjsharath28. 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-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pjsharath28 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test |
Actually, I feel using |
@pjsharath28: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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-sigs/prow repository. I understand the commands that are listed here. |
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.
Please rebase for the recent changes and replace require
library calls as well
@@ -936,7 +936,9 @@ func TestPlugin(t *testing.T) { | |||
|
|||
result, status := testCtx.p.PreFilter(testCtx.ctx, testCtx.state, tc.pod) | |||
t.Run("prefilter", func(t *testing.T) { | |||
assert.Equal(t, tc.want.preFilterResult, result) | |||
if diff := cmp.Diff(tc.want.preFilterResult, result); diff != "" { | |||
t.Errorf("Mismatch in Prefilter (- expected, + actual):\n%s", diff) |
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.
t.Errorf("Mismatch in Prefilter (- expected, + actual):\n%s", diff) | |
t.Errorf("Unexpected PreFilter result (-want,+got):\n%s", diff) |
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.
And change in other as well
expectedErr := expected.status.AsError() | ||
if expectedErr != nil { | ||
if diff := cmp.Diff(expectedErr.Error(), actualErr.Error()); diff != "" { | ||
t.Errorf("Mismatch in error strings (- expected, + actual):\n%s", diff) | ||
} | ||
} else { | ||
t.Errorf("Expected no error, but got: %v", actualErr) | ||
} |
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.
Use cmp.Equal to compare strings:
expectedErr := expected.status.AsError() | |
if expectedErr != nil { | |
if diff := cmp.Diff(expectedErr.Error(), actualErr.Error()); diff != "" { | |
t.Errorf("Mismatch in error strings (- expected, + actual):\n%s", diff) | |
} | |
} else { | |
t.Errorf("Expected no error, but got: %v", actualErr) | |
} | |
expectedErr := expected.status.AsError() | |
if !cmp.Equal(expectedErr.Error(), actualErr.Error()) { | |
t.Errorf("Expected status error: %s, got: %s", expectedErr, actualErr) | |
} |
@@ -809,7 +812,9 @@ func TestVolumeBinding(t *testing.T) { | |||
t.Logf("Verify: call Filter and check status") | |||
for i, nodeInfo := range nodeInfos { | |||
gotStatus := p.Filter(ctx, state, item.pod, nodeInfo) | |||
assert.Equal(t, item.wantFilterStatus[i], gotStatus) | |||
if diff := cmp.Diff(item.wantFilterStatus[i], gotStatus); diff != "" { | |||
t.Errorf("Mismatch in wantFilterStatus[%d] (-want,+got):\n%s", i, diff) |
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.
t.Errorf("Mismatch in wantFilterStatus[%d] (-want,+got):\n%s", i, diff) | |
t.Errorf("Unexpected Filter status for node %s (-want,+got):\n%s", nodeInfo.Node().Name, diff) |
actual := function(assertion.p) | ||
delta := 0.1 | ||
expectedAsFloat := float64(assertion.expected) | ||
actualAsFloat := float64(actual) | ||
if (expectedAsFloat-actualAsFloat) > delta || (actualAsFloat-expectedAsFloat) > delta { | ||
t.Errorf("Mismatch in values with delta threshold (%.2f): expected %.2f, actual %.2f", delta, expectedAsFloat, actualAsFloat) | ||
} |
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.
Checking delta in this test doesn't make sense at all. We have two ints, so if they are equal the test will pass, but it they are not, it will always fail. It could be just an equality check here:
actual := function(assertion.p) | |
delta := 0.1 | |
expectedAsFloat := float64(assertion.expected) | |
actualAsFloat := float64(actual) | |
if (expectedAsFloat-actualAsFloat) > delta || (actualAsFloat-expectedAsFloat) > delta { | |
t.Errorf("Mismatch in values with delta threshold (%.2f): expected %.2f, actual %.2f", delta, expectedAsFloat, actualAsFloat) | |
} | |
if actual := function(assertion.p); actual != assertion.expected { | |
t.Errorf(...) | |
} |
if !cmp.Equal(c, nil) { | ||
t.Errorf("Expected nil, but got: %+v", c) | ||
} | ||
|
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.
It seems like the nil check is redundant, you could use underscore above:
var _ frameworkContract = f
Code won't compile if the contract is not satisfied
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.
Probably these two lines could be moved outside of the function, as package variables
PR needs rebase. 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-sigs/prow repository. |
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
What type of PR is this?
/kind cleanup
/sig scheduling
What this PR does / why we need it:
Removed the usage of assertion libraries as per the style guide
Which issue(s) this PR fixes:
Fixes #130407
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: