sigs.k8s.io/cluster-api-provider-azure@v1.14.3/util/maps/maps_test.go (about) 1 /* 2 Copyright 2022 The Kubernetes 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 maps 18 19 import ( 20 "testing" 21 22 "github.com/onsi/gomega" 23 ) 24 25 func TestMerge(t *testing.T) { 26 tests := []struct { 27 name string 28 base map[string]string 29 overrides map[string]string 30 expected map[string]string 31 }{ 32 { 33 name: "nil base", 34 base: nil, 35 overrides: map[string]string{"key": "value"}, 36 expected: map[string]string{"key": "value"}, 37 }, 38 { 39 name: "nil overrides", 40 base: map[string]string{"key": "value"}, 41 overrides: nil, 42 expected: map[string]string{"key": "value"}, 43 }, 44 { 45 name: "overrides takes precedence", 46 base: map[string]string{"key": "base"}, 47 overrides: map[string]string{"key": "overrides"}, 48 expected: map[string]string{"key": "overrides"}, 49 }, 50 { 51 name: "non-overlapping keys are all preserved", 52 base: map[string]string{"base": "value"}, 53 overrides: map[string]string{"overrides": "value"}, 54 expected: map[string]string{"base": "value", "overrides": "value"}, 55 }, 56 } 57 58 for _, test := range tests { 59 t.Run(test.name, func(t *testing.T) { 60 g := gomega.NewWithT(t) 61 g.Expect(Merge(test.base, test.overrides)).To(gomega.Equal(test.expected)) 62 }) 63 } 64 }