Skip to content

Commit

Permalink
Add DotToObj tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supercairos committed Mar 20, 2024
1 parent 021a554 commit d927e34
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,12 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
}

func dotToObj(key string, value string) map[string]interface{} {
keys := strings.Split(key, ".")
obj := make(map[string]interface{})
if key == "" {
return obj
}

keys := strings.Split(key, ".")

current := obj
for i, k := range keys {
Expand Down
22 changes: 22 additions & 0 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,28 @@ random:
})
}

func Test_DotToObj(t *testing.T) {
t.Run("no value", func(t *testing.T) {
obj := dotToObj("", "val")
assert.Equal(t, map[string]interface{}{}, obj)
})

t.Run("single value", func(t *testing.T) {
obj := dotToObj("a", "val")
assert.Equal(t, map[string]interface{}{"a": "val"}, obj)
})

t.Run("multiple values", func(t *testing.T) {
obj := dotToObj("a.b.c", "val")
assert.Equal(t, map[string]interface{}{"a": map[string]interface{}{
"b": map[string]interface{}{
"c": "val",
},
},
}, obj)
})
}

func Test_GetWriteBackConfig(t *testing.T) {
t.Run("Valid write-back config - git", func(t *testing.T) {
app := v1alpha1.Application{
Expand Down

0 comments on commit d927e34

Please sign in to comment.