Unverified Commit 07240b71 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #60555 from zhangxiaoyu-zidif/add-unit-test-for-nodenames-slice-comparison

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. add unit test case for nodenames comparison **What this PR does / why we need it**: ref https://github.com/kubernetes/kubernetes/pull/60486 **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: please merge it after https://github.com/kubernetes/kubernetes/pull/60486 **Release note**: ```release-note NONE ```
parents f89d0fa5 a0786a2d
...@@ -777,13 +777,21 @@ func TestServiceCache(t *testing.T) { ...@@ -777,13 +777,21 @@ func TestServiceCache(t *testing.T) {
//Test a utility functions as its not easy to unit test nodeSyncLoop directly //Test a utility functions as its not easy to unit test nodeSyncLoop directly
func TestNodeSlicesEqualForLB(t *testing.T) { func TestNodeSlicesEqualForLB(t *testing.T) {
numNodes := 10 numNodes := 10
nArray := make([]*v1.Node, 10) nArray := make([]*v1.Node, numNodes)
mArray := make([]*v1.Node, numNodes)
for i := 0; i < numNodes; i++ { for i := 0; i < numNodes; i++ {
nArray[i] = &v1.Node{} nArray[i] = &v1.Node{}
nArray[i].Name = fmt.Sprintf("node1") nArray[i].Name = fmt.Sprintf("node%d", i)
}
for i := 0; i < numNodes; i++ {
mArray[i] = &v1.Node{}
mArray[i].Name = fmt.Sprintf("node%d", i+1)
} }
if !nodeSlicesEqualForLB(nArray, nArray) { if !nodeSlicesEqualForLB(nArray, nArray) {
t.Errorf("nodeSlicesEqualForLB() Expected=true Obtained=false") t.Errorf("nodeSlicesEqualForLB() Expected=true Obtained=false")
} }
if nodeSlicesEqualForLB(nArray, mArray) {
t.Errorf("nodeSlicesEqualForLB() Expected=false Obtained=true")
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment