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
```
pull/6/head
Kubernetes Submit Queue 2018-02-28 10:39:18 -08:00 committed by GitHub
commit 07240b7166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -777,13 +777,21 @@ func TestServiceCache(t *testing.T) {
//Test a utility functions as its not easy to unit test nodeSyncLoop directly
func TestNodeSlicesEqualForLB(t *testing.T) {
numNodes := 10
nArray := make([]*v1.Node, 10)
nArray := make([]*v1.Node, numNodes)
mArray := make([]*v1.Node, numNodes)
for i := 0; i < numNodes; i++ {
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) {
t.Errorf("nodeSlicesEqualForLB() Expected=true Obtained=false")
}
if nodeSlicesEqualForLB(nArray, mArray) {
t.Errorf("nodeSlicesEqualForLB() Expected=false Obtained=true")
}
}