summaryrefslogtreecommitdiff
path: root/pkg/argocd/update_test.go
diff options
context:
space:
mode:
authorCheng Fang <cfang@redhat.com>2024-10-18 02:25:32 -0400
committerGitHub <noreply@github.com>2024-10-18 09:25:32 +0300
commit4f21adef41a9dfad16ac6c1d7d7f53bc67e8a79d (patch)
tree202a8263b9a395191ccb4445e1e77435411fc40f /pkg/argocd/update_test.go
parent02eee1d750f44e7275eff4c1630580badbc08058 (diff)
fix: Git write back to helm values is incorrect during the first pass and corrupts existing data (#885)
Signed-off-by: Cheng Fang <cfang@redhat.com>
Diffstat (limited to 'pkg/argocd/update_test.go')
-rw-r--r--pkg/argocd/update_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go
index 5d026fc..416de5d 100644
--- a/pkg/argocd/update_test.go
+++ b/pkg/argocd/update_test.go
@@ -1500,6 +1500,20 @@ replicas: 1
require.NoError(t, err)
assert.NotEmpty(t, yaml)
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
+
+ // when image.spec.foo fields are missing in the target helm value file,
+ // they should be auto created without corrupting any other pre-existing elements.
+ originalData = []byte("test-value1: one")
+ expected = `
+test-value1: one
+image:
+ spec:
+ foo: nginx:v1.0.0
+`
+ yaml, err = marshalParamsOverride(&app, originalData)
+ require.NoError(t, err)
+ assert.NotEmpty(t, yaml)
+ assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
})
t.Run("Valid Helm source with Helm values file with multiple images", func(t *testing.T) {
@@ -1588,6 +1602,25 @@ replicas: 1
require.NoError(t, err)
assert.NotEmpty(t, yaml)
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
+
+ // when nginx.* and redis.* fields are missing in the target helm value file,
+ // they should be auto created without corrupting any other pre-existing elements.
+ originalData = []byte("test-value1: one")
+ expected = `
+test-value1: one
+nginx:
+ image:
+ tag: v1.0.0
+ name: nginx
+redis:
+ image:
+ tag: v1.0.0
+ name: redis
+`
+ yaml, err = marshalParamsOverride(&app, originalData)
+ require.NoError(t, err)
+ assert.NotEmpty(t, yaml)
+ assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
})
t.Run("Valid Helm source with Helm values file with multiple aliases", func(t *testing.T) {
@@ -1695,6 +1728,7 @@ replicas: 1
t.Run("Failed to setValue image parameter name", func(t *testing.T) {
expected := `
+test-value1: one
image:
name: nginx
tag: v1.0.0
@@ -1743,6 +1777,7 @@ replicas: 1
}
originalData := []byte(`
+test-value1: one
image:
name: nginx
replicas: 1