chore(refactor): simplify maps util (#23431)

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
This commit is contained in:
Michael Crenshaw
2025-06-16 16:29:45 -04:00
committed by GitHub
parent ede2b32aea
commit 30c325d952
3 changed files with 7 additions and 16 deletions

View File

@@ -71,7 +71,7 @@ func (m *MatrixGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.App
if err != nil {
return nil, fmt.Errorf("failed to combine string maps with merging params for the matrix generator: %w", err)
}
res = append(res, utils.ConvertToMapStringInterface(val))
res = append(res, val)
}
}
}

View File

@@ -13,20 +13,11 @@ func ConvertToMapStringString(mapStringInterface map[string]any) map[string]stri
return mapStringString
}
func ConvertToMapStringInterface(mapStringString map[string]string) map[string]any {
mapStringInterface := make(map[string]any, len(mapStringString))
for key, value := range mapStringString {
mapStringInterface[key] = value
}
return mapStringInterface
}
func CombineStringMaps(aSI map[string]any, bSI map[string]any) (map[string]string, error) {
func CombineStringMaps(aSI map[string]any, bSI map[string]any) (map[string]any, error) {
a := ConvertToMapStringString(aSI)
b := ConvertToMapStringString(bSI)
res := map[string]string{}
res := map[string]any{}
for k, v := range a {
res[k] = v

View File

@@ -15,28 +15,28 @@ func TestCombineStringMaps(t *testing.T) {
name string
left map[string]any
right map[string]any
expected map[string]string
expected map[string]any
expectedErr error
}{
{
name: "combines the maps",
left: map[string]any{"foo": "bar"},
right: map[string]any{"a": "b"},
expected: map[string]string{"a": "b", "foo": "bar"},
expected: map[string]any{"a": "b", "foo": "bar"},
expectedErr: nil,
},
{
name: "fails if keys are the same but value isn't",
left: map[string]any{"foo": "bar", "a": "fail"},
right: map[string]any{"a": "b", "c": "d"},
expected: map[string]string{"a": "b", "foo": "bar"},
expected: map[string]any{"a": "b", "foo": "bar"},
expectedErr: errors.New("found duplicate key a with different value, a: fail ,b: b"),
},
{
name: "pass if keys & values are the same",
left: map[string]any{"foo": "bar", "a": "b"},
right: map[string]any{"a": "b", "c": "d"},
expected: map[string]string{"a": "b", "c": "d", "foo": "bar"},
expected: map[string]any{"a": "b", "c": "d", "foo": "bar"},
expectedErr: nil,
},
}