...
1
16
17 package values
18
19 import (
20 "reflect"
21 "testing"
22
23 "helm.sh/helm/v3/pkg/getter"
24 )
25
26 func TestMergeValues(t *testing.T) {
27 nestedMap := map[string]interface{}{
28 "foo": "bar",
29 "baz": map[string]string{
30 "cool": "stuff",
31 },
32 }
33 anotherNestedMap := map[string]interface{}{
34 "foo": "bar",
35 "baz": map[string]string{
36 "cool": "things",
37 "awesome": "stuff",
38 },
39 }
40 flatMap := map[string]interface{}{
41 "foo": "bar",
42 "baz": "stuff",
43 }
44 anotherFlatMap := map[string]interface{}{
45 "testing": "fun",
46 }
47
48 testMap := mergeMaps(flatMap, nestedMap)
49 equal := reflect.DeepEqual(testMap, nestedMap)
50 if !equal {
51 t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", nestedMap, testMap)
52 }
53
54 testMap = mergeMaps(nestedMap, flatMap)
55 equal = reflect.DeepEqual(testMap, flatMap)
56 if !equal {
57 t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", flatMap, testMap)
58 }
59
60 testMap = mergeMaps(nestedMap, anotherNestedMap)
61 equal = reflect.DeepEqual(testMap, anotherNestedMap)
62 if !equal {
63 t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", anotherNestedMap, testMap)
64 }
65
66 testMap = mergeMaps(anotherFlatMap, anotherNestedMap)
67 expectedMap := map[string]interface{}{
68 "testing": "fun",
69 "foo": "bar",
70 "baz": map[string]string{
71 "cool": "things",
72 "awesome": "stuff",
73 },
74 }
75 equal = reflect.DeepEqual(testMap, expectedMap)
76 if !equal {
77 t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap)
78 }
79 }
80
81 func TestReadFile(t *testing.T) {
82 var p getter.Providers
83 filePath := "%a.txt"
84 _, err := readFile(filePath, p)
85 if err == nil {
86 t.Errorf("Expected error when has special strings")
87 }
88 }
89
View as plain text