github.com/kruglovmax/helm@v3.0.0-beta.3+incompatible/pkg/cli/values/options_test.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package values 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestMergeValues(t *testing.T) { 25 nestedMap := map[string]interface{}{ 26 "foo": "bar", 27 "baz": map[string]string{ 28 "cool": "stuff", 29 }, 30 } 31 anotherNestedMap := map[string]interface{}{ 32 "foo": "bar", 33 "baz": map[string]string{ 34 "cool": "things", 35 "awesome": "stuff", 36 }, 37 } 38 flatMap := map[string]interface{}{ 39 "foo": "bar", 40 "baz": "stuff", 41 } 42 anotherFlatMap := map[string]interface{}{ 43 "testing": "fun", 44 } 45 46 testMap := mergeMaps(flatMap, nestedMap) 47 equal := reflect.DeepEqual(testMap, nestedMap) 48 if !equal { 49 t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", nestedMap, testMap) 50 } 51 52 testMap = mergeMaps(nestedMap, flatMap) 53 equal = reflect.DeepEqual(testMap, flatMap) 54 if !equal { 55 t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", flatMap, testMap) 56 } 57 58 testMap = mergeMaps(nestedMap, anotherNestedMap) 59 equal = reflect.DeepEqual(testMap, anotherNestedMap) 60 if !equal { 61 t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", anotherNestedMap, testMap) 62 } 63 64 testMap = mergeMaps(anotherFlatMap, anotherNestedMap) 65 expectedMap := map[string]interface{}{ 66 "testing": "fun", 67 "foo": "bar", 68 "baz": map[string]string{ 69 "cool": "things", 70 "awesome": "stuff", 71 }, 72 } 73 equal = reflect.DeepEqual(testMap, expectedMap) 74 if !equal { 75 t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap) 76 } 77 }