mirror of https://github.com/kubernetes/kops.git
Replace template text with something that builde the entire context
This commit is contained in:
parent
64334eba00
commit
b6a07c16fe
|
|
@ -0,0 +1,4 @@
|
||||||
|
Foo: "bar"
|
||||||
|
Bar:
|
||||||
|
Foo:
|
||||||
|
Bar: "foo"
|
||||||
|
|
@ -17,63 +17,12 @@ limitations under the License.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Copied from the Helm (https://github.com/kubernetes/helm) project:
|
func TestNewTemplateContext(t *testing.T) {
|
||||||
// https://github.com/kubernetes/helm/blob/282984e75fd115a0765730efe09d8257c72fa56d/cmd/helm/install_test.go#L230
|
context, _ := newTemplateContext([]string{"test/values.yaml"}, []string{"Foo=baz"}, []string{})
|
||||||
func TestMergeValues(t *testing.T) {
|
if context["Foo"] != "baz" {
|
||||||
nestedMap := map[string]interface{}{
|
t.Errorf("Got %v, expected baz", context["foo"])
|
||||||
"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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue