-
Notifications
You must be signed in to change notification settings - Fork 871
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
Added tests for pkg/servicenameresolutiondetector #5408
Added tests for pkg/servicenameresolutiondetector #5408
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #5408 +/- ##
==========================================
+ Coverage 29.67% 30.59% +0.91%
==========================================
Files 632 632
Lines 43936 43936
==========================================
+ Hits 13037 13441 +404
+ Misses 29954 29518 -436
- Partials 945 977 +32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
8a2571a
to
3111a59
Compare
/assign |
@XiShanYongYe-Chang Please take a look. |
for _, status := range tt.expectedStatus { | ||
if condition.Status == status { | ||
validStatus = true | ||
break |
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.
We can add a check: when condition.Status = metav1.ConditionFalse
, check whether condition.Reason = serviceDomainNameResolutionFailed
.
name string | ||
alarm bool | ||
expectedStatus metav1.ConditionStatus | ||
expectedReason 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.
expectedReason string | |
expectedReason string | |
expectedMessage string |
case "ListAll": | ||
result, opErr = store.ListAll() |
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.
case "ListAll": | |
result, opErr = store.ListAll() |
expectedError bool | ||
}{ | ||
{ | ||
name: "Load existing node condition", |
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.
Add a case where the node exists, but the conditionType
of the node does not match the store.
}, | ||
}, | ||
expectedResult: []metav1.Condition{ | ||
{Type: string(corev1.NodeReady), Status: metav1.ConditionTrue}, |
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.
listAll
function does not guarantee that the returned result will maintain the same order as the input nodes
, which can lead to intermittent test failures.
=== RUN TestNodeStore_ListAll/List_with_not_ready_and_stale_nodes
node_store_test.go:249:
Error Trace: /root/home/workspace/code/karmada/pkg/servicenameresolutiondetector/store/node_store_test.go:249
Error: Not equal:
expected: "True"
actual : "Unknown"
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,2 @@
-(v1.ConditionStatus) (len=4) "True"
+(v1.ConditionStatus) (len=7) "Unknown"
Test: TestNodeStore_ListAll/List_with_not_ready_and_stale_nodes
node_store_test.go:249:
Error Trace: /root/home/workspace/code/karmada/pkg/servicenameresolutiondetector/store/node_store_test.go:249
Error: Not equal:
expected: "Unknown"
actual : "True"
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,2 @@
-(v1.ConditionStatus) (len=7) "Unknown"
+(v1.ConditionStatus) (len=4) "True"
Test: TestNodeStore_ListAll/List_with_not_ready_and_stale_nodes
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 can sort the results before comparing.
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.
Looks like you are converting the result array into a map to avoid ordering issues, which makes sense to me
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.
Can we move ahead with it?
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.
yes, please go ahead
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.
@zhzhuang-zju can you trigger a retest?
3111a59
to
dd5ba22
Compare
dd5ba22
to
ef6fa6b
Compare
ef6fa6b
to
7ba7812
Compare
Hi @anujagrawal699, can you help squash the commits into one? |
Hey @XiShanYongYe-Chang can you check if the current TestNodeStore_ListAll function is correct as mentioned by @zhzhuang-zju in the review. I'll squash commit after making the necessary changes. |
Signed-off-by: Anuj Agrawal <[email protected]> Added tests for pkg/servicenameresolutiondetector Signed-off-by: Anuj Agrawal <[email protected]> Added tests for pkg/servicenameresolutiondetector Signed-off-by: Anuj Agrawal <[email protected]> Added tests for pkg/servicenameresolutiondetector Signed-off-by: Anuj Agrawal <[email protected]>
00dc3d6
to
147ede0
Compare
/retest |
} | ||
} | ||
|
||
func TestSetNodeStatusCondition(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.
Hey @anujagrawal699 , do we have tested FindNodeStatusCondition function explicitly ?
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.
No, we haven't. The size of PR was going big as you see (1000+ lines) and i though of another pr on pkg/servicenameresolutiondetector after i complete pending tests on another packages.
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.
@yashpandey06 But still the FindNodeStatusCondition function is being indirectly tested within the TestNodeStore function.
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 it's indirectly tested , that would suffice the need for now 😃
/assign |
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~
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: XiShanYongYe-Chang 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 |
Description:
This PR introduces tests for servicenameresolutiondetector package covering all the modules in each directory of it.
Additions:*
Test Coverage:
The servicenameresolutiondetector package had a test coverage of 0.00%. The PR enhances its overall test coverage to more than 80%. The test coverage of pkg/servicenameresolutiondetector/coredns is enhanced to 74.3% and of pkg/servicenameresolutiondetector/store to 90.3%. This can be verified using
go test ./... -coverprofile=coverage.out
in the pkg/servicenameresolutiondetector directory.What type of PR is this?
/kind failing-test
/kind feature
What this PR does / why we need it:
This PR adds comprehensive tests to the servicenameresolutiondetector package, improving the overall test coverage and ensuring the reliability and maintainability of the codebase.
Which issue(s) this PR fixes:
Fixes a part of #5235
Does this PR introduce a user-facing change?: