github.com/argoproj/argo-cd/v3@v3.2.1/applicationset/utils/map_test.go (about) 1 package utils 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestCombineStringMaps(t *testing.T) { 12 t.Parallel() 13 14 testCases := []struct { 15 name string 16 left map[string]any 17 right map[string]any 18 expected map[string]any 19 expectedErr error 20 }{ 21 { 22 name: "combines the maps", 23 left: map[string]any{"foo": "bar"}, 24 right: map[string]any{"a": "b"}, 25 expected: map[string]any{"a": "b", "foo": "bar"}, 26 expectedErr: nil, 27 }, 28 { 29 name: "fails if keys are the same but value isn't", 30 left: map[string]any{"foo": "bar", "a": "fail"}, 31 right: map[string]any{"a": "b", "c": "d"}, 32 expected: map[string]any{"a": "b", "foo": "bar"}, 33 expectedErr: errors.New("found duplicate key a with different value, a: fail ,b: b"), 34 }, 35 { 36 name: "pass if keys & values are the same", 37 left: map[string]any{"foo": "bar", "a": "b"}, 38 right: map[string]any{"a": "b", "c": "d"}, 39 expected: map[string]any{"a": "b", "c": "d", "foo": "bar"}, 40 expectedErr: nil, 41 }, 42 } 43 44 for _, testCase := range testCases { 45 testCaseCopy := testCase 46 47 t.Run(testCaseCopy.name, func(t *testing.T) { 48 t.Parallel() 49 50 got, err := CombineStringMaps(testCaseCopy.left, testCaseCopy.right) 51 52 if testCaseCopy.expectedErr != nil { 53 assert.EqualError(t, err, testCaseCopy.expectedErr.Error()) 54 } else { 55 require.NoError(t, err) 56 assert.Equal(t, testCaseCopy.expected, got) 57 } 58 }) 59 } 60 }