Skip to content

Commit 2d93761

Browse files
committed
fix tests
1 parent c1bf3c3 commit 2d93761

File tree

3 files changed

+21
-50
lines changed

3 files changed

+21
-50
lines changed

pkg/argocd/argocd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func getHelmParamNamesFromAnnotation(annotations map[string]string, img *image.C
336336
// Get a named helm parameter from a list of parameters
337337
func getHelmParam(params []v1alpha1.HelmParameter, name string) *v1alpha1.HelmParameter {
338338
for _, param := range params {
339-
if param.Name == name {
339+
if param.Name == strings.Trim(name, "'\"") {
340340
return &param
341341
}
342342
}

pkg/argocd/update.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,16 @@ func setHelmValue(file *ast.File, keyPath, value string) error {
591591
return fmt.Errorf("empty key provided")
592592
}
593593

594-
mapping, ok := file.Docs[0].Body.(*ast.MappingNode)
595-
if !ok {
594+
var mapping *ast.MappingNode
595+
if file.Docs[0].Body == nil {
596596
tk := token.New("$", "$", &token.Position{})
597597
mapping = ast.Mapping(tk, false)
598598
file.Docs[0].Body = mapping
599+
} else {
600+
mapping, _ = file.Docs[0].Body.(*ast.MappingNode)
601+
if mapping == nil {
602+
return fmt.Errorf("yaml is invalid")
603+
}
599604
}
600605

601606
// Traverse the path

pkg/argocd/update_test.go

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,6 @@ helm:
12501250
parameters:
12511251
- name: baz
12521252
value: baz
1253-
forceString: false
12541253
- name: foo
12551254
value: bar
12561255
forceString: true
@@ -1444,8 +1443,8 @@ replicas: 1
14441443
"argocd-image-updater.argoproj.io/image-list": "nginx",
14451444
"argocd-image-updater.argoproj.io/write-back-method": "git",
14461445
"argocd-image-updater.argoproj.io/write-back-target": "helmvalues:./test-values.yaml",
1447-
"argocd-image-updater.argoproj.io/nginx.helm.image-name": "image.name",
1448-
"argocd-image-updater.argoproj.io/nginx.helm.image-tag": "image.tag",
1446+
"argocd-image-updater.argoproj.io/nginx.helm.image-name": "'image.name'",
1447+
"argocd-image-updater.argoproj.io/nginx.helm.image-tag": "'image.tag'",
14491448
},
14501449
},
14511450
Spec: v1alpha1.ApplicationSpec{
@@ -1501,7 +1500,7 @@ replicas: 1
15011500
"argocd-image-updater.argoproj.io/image-list": "nginx",
15021501
"argocd-image-updater.argoproj.io/write-back-method": "git",
15031502
"argocd-image-updater.argoproj.io/write-back-target": "helmvalues:./test-values.yaml",
1504-
"argocd-image-updater.argoproj.io/nginx.helm.image-spec": "image.spec.foo",
1503+
"argocd-image-updater.argoproj.io/nginx.helm.image-spec": "'image.spec.foo'",
15051504
},
15061505
},
15071506
Spec: v1alpha1.ApplicationSpec{
@@ -1537,20 +1536,6 @@ replicas: 1
15371536
require.NoError(t, err)
15381537
assert.NotEmpty(t, yaml)
15391538
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
1540-
1541-
// when image.spec.foo fields are missing in the target helm value file,
1542-
// they should be auto created without corrupting any other pre-existing elements.
1543-
originalData = []byte("test-value1: one")
1544-
expected = `
1545-
test-value1: one
1546-
image:
1547-
spec:
1548-
foo: nginx:v1.0.0
1549-
`
1550-
yaml, err = marshalParamsOverride(&app, originalData)
1551-
require.NoError(t, err)
1552-
assert.NotEmpty(t, yaml)
1553-
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
15541539
})
15551540

15561541
t.Run("Valid Helm source with Helm values file with multiple images", func(t *testing.T) {
@@ -1568,10 +1553,10 @@ replicas: 1
15681553
"argocd-image-updater.argoproj.io/image-list": "nginx=nginx, redis=redis",
15691554
"argocd-image-updater.argoproj.io/write-back-method": "git",
15701555
"argocd-image-updater.argoproj.io/write-back-target": "helmvalues:./test-values.yaml",
1571-
"argocd-image-updater.argoproj.io/nginx.helm.image-name": "nginx.image.name",
1572-
"argocd-image-updater.argoproj.io/nginx.helm.image-tag": "nginx.image.tag",
1573-
"argocd-image-updater.argoproj.io/redis.helm.image-name": "redis.image.name",
1574-
"argocd-image-updater.argoproj.io/redis.helm.image-tag": "redis.image.tag",
1556+
"argocd-image-updater.argoproj.io/nginx.helm.image-name": "'nginx.image.name'",
1557+
"argocd-image-updater.argoproj.io/nginx.helm.image-tag": "'nginx.image.tag'",
1558+
"argocd-image-updater.argoproj.io/redis.helm.image-name": "'redis.image.name'",
1559+
"argocd-image-updater.argoproj.io/redis.helm.image-tag": "'redis.image.tag'",
15751560
},
15761561
},
15771562
Spec: v1alpha1.ApplicationSpec{
@@ -1639,25 +1624,6 @@ replicas: 1
16391624
require.NoError(t, err)
16401625
assert.NotEmpty(t, yaml)
16411626
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
1642-
1643-
// when nginx.* and redis.* fields are missing in the target helm value file,
1644-
// they should be auto created without corrupting any other pre-existing elements.
1645-
originalData = []byte("test-value1: one")
1646-
expected = `
1647-
test-value1: one
1648-
nginx:
1649-
image:
1650-
tag: v1.0.0
1651-
name: nginx
1652-
redis:
1653-
image:
1654-
tag: v1.0.0
1655-
name: redis
1656-
`
1657-
yaml, err = marshalParamsOverride(&app, originalData)
1658-
require.NoError(t, err)
1659-
assert.NotEmpty(t, yaml)
1660-
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
16611627
})
16621628

16631629
t.Run("Valid Helm source with Helm values file with multiple aliases", func(t *testing.T) {
@@ -1677,12 +1643,12 @@ replicas: 1
16771643
"argocd-image-updater.argoproj.io/image-list": "foo=nginx, bar=nginx, bbb=nginx",
16781644
"argocd-image-updater.argoproj.io/write-back-method": "git",
16791645
"argocd-image-updater.argoproj.io/write-back-target": "helmvalues:./test-values.yaml",
1680-
"argocd-image-updater.argoproj.io/foo.helm.image-name": "foo.image.name",
1681-
"argocd-image-updater.argoproj.io/foo.helm.image-tag": "foo.image.tag",
1682-
"argocd-image-updater.argoproj.io/bar.helm.image-name": "bar.image.name",
1683-
"argocd-image-updater.argoproj.io/bar.helm.image-tag": "bar.image.tag",
1684-
"argocd-image-updater.argoproj.io/bbb.helm.image-name": "bbb.image.name",
1685-
"argocd-image-updater.argoproj.io/bbb.helm.image-tag": "bbb.image.tag",
1646+
"argocd-image-updater.argoproj.io/foo.helm.image-name": "'foo.image.name'",
1647+
"argocd-image-updater.argoproj.io/foo.helm.image-tag": "'foo.image.tag'",
1648+
"argocd-image-updater.argoproj.io/bar.helm.image-name": "'bar.image.name'",
1649+
"argocd-image-updater.argoproj.io/bar.helm.image-tag": "'bar.image.tag'",
1650+
"argocd-image-updater.argoproj.io/bbb.helm.image-name": "'bbb.image.name'",
1651+
"argocd-image-updater.argoproj.io/bbb.helm.image-tag": "'bbb.image.tag'",
16861652
},
16871653
},
16881654
Spec: v1alpha1.ApplicationSpec{

0 commit comments

Comments
 (0)