Skip to content

Commit

Permalink
Update unit test to ignore ordering of labels generated by constructN…
Browse files Browse the repository at this point in the history
…odeSelector() (#1673)

* Update unit test to ignore ordering of labels generated by constructNodeSelector()

* Updates unit test in yaml_factory_test.go to fix failures due to output ordering of the generated selector labels.

closes ut_label_ordering_fix

* address PR comments
  • Loading branch information
vivintw authored Jul 23, 2024
1 parent b592682 commit 722e7ef
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions cli/k8s_client/yaml_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,30 @@ func TestGetCSIDaemonSetYAMLWindows_Tolerations(t *testing.T) {
}

func TestConstructNodeSelector(t *testing.T) {
nodeSelMap := map[string]string{"node-label-name": "master", "node-label-number": "20", "node-label-bool": "true", "node-label-alphanum": "alph20"}
nodeSelMap := map[string]string{
"node-label-name": "master",
"node-label-number": "20",
"node-label-bool": "true",
"node-label-alphanum": "alph20",
}

expectedNodeSelString := []string{"- key: node-label-name\n operator: In\n values:\n - 'master'\n", "- key: node-label-number\n operator: In\n values:\n - '20'\n", "- key: node-label-bool\n operator: In\n values:\n - 'true'\n", "- key: node-label-alphanum\n operator: In\n values:\n - 'alph20'\n"}
expectedNodeSelStrings := []string{
"- key: node-label-name\n operator: In\n values:\n - 'master'\n",
"- key: node-label-number\n operator: In\n values:\n - '20'\n",
"- key: node-label-bool\n operator: In\n values:\n - 'true'\n",
"- key: node-label-alphanum\n operator: In\n values:\n - 'alph20'\n",
}

result := constructNodeSelector(nodeSelMap)
expectedString := strings.Join(expectedNodeSelString, "")
assert.Equal(t, expectedString, result)
// verify all the expected strings are present in the result
for _, expectedString := range expectedNodeSelStrings {
assert.Contains(t, result, expectedString)
before, after, _ := strings.Cut(result, expectedString)
result = before + after
}

// verify that the result does not contain anything else other than what is expected.
assert.Empty(t, result)
}

func TestGetNamespaceYAML(t *testing.T) {
Expand Down

0 comments on commit 722e7ef

Please sign in to comment.