diff --git a/cli/k8s_client/yaml_factory_test.go b/cli/k8s_client/yaml_factory_test.go index 34804f422..773ebcf0a 100644 --- a/cli/k8s_client/yaml_factory_test.go +++ b/cli/k8s_client/yaml_factory_test.go @@ -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) {