From b6a07c16fec29517b0ccdc00a9d985622356be75 Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Tue, 15 Dec 2020 16:08:21 +0100 Subject: [PATCH] Replace template text with something that builde the entire context --- cmd/kops/test/values.yaml | 4 +++ cmd/kops/toolbox_template_test.go | 59 +++---------------------------- 2 files changed, 8 insertions(+), 55 deletions(-) create mode 100644 cmd/kops/test/values.yaml diff --git a/cmd/kops/test/values.yaml b/cmd/kops/test/values.yaml new file mode 100644 index 0000000000..fcd0292009 --- /dev/null +++ b/cmd/kops/test/values.yaml @@ -0,0 +1,4 @@ +Foo: "bar" +Bar: + Foo: + Bar: "foo" \ No newline at end of file diff --git a/cmd/kops/toolbox_template_test.go b/cmd/kops/toolbox_template_test.go index 0bc28b5cd4..030cccbf1f 100644 --- a/cmd/kops/toolbox_template_test.go +++ b/cmd/kops/toolbox_template_test.go @@ -17,63 +17,12 @@ limitations under the License. package main import ( - "reflect" "testing" ) -// Copied from the Helm (https://github.com/kubernetes/helm) project: -// https://github.com/kubernetes/helm/blob/282984e75fd115a0765730efe09d8257c72fa56d/cmd/helm/install_test.go#L230 -func TestMergeValues(t *testing.T) { - nestedMap := map[string]interface{}{ - "foo": "bar", - "baz": map[string]string{ - "cool": "stuff", - }, - } - anotherNestedMap := map[string]interface{}{ - "foo": "bar", - "baz": map[string]string{ - "cool": "things", - "awesome": "stuff", - }, - } - flatMap := map[string]interface{}{ - "foo": "bar", - "baz": "stuff", - } - anotherFlatMap := map[string]interface{}{ - "testing": "fun", - } - - testMap := mergeValues(flatMap, nestedMap) - equal := reflect.DeepEqual(testMap, nestedMap) - if !equal { - t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", nestedMap, testMap) - } - - testMap = mergeValues(nestedMap, flatMap) - equal = reflect.DeepEqual(testMap, flatMap) - if !equal { - t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", flatMap, testMap) - } - - testMap = mergeValues(nestedMap, anotherNestedMap) - equal = reflect.DeepEqual(testMap, anotherNestedMap) - if !equal { - t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", anotherNestedMap, testMap) - } - - testMap = mergeValues(anotherFlatMap, anotherNestedMap) - expectedMap := map[string]interface{}{ - "testing": "fun", - "foo": "bar", - "baz": map[string]string{ - "cool": "things", - "awesome": "stuff", - }, - } - equal = reflect.DeepEqual(testMap, expectedMap) - if !equal { - t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap) +func TestNewTemplateContext(t *testing.T) { + context, _ := newTemplateContext([]string{"test/values.yaml"}, []string{"Foo=baz"}, []string{}) + if context["Foo"] != "baz" { + t.Errorf("Got %v, expected baz", context["foo"]) } }