Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Caire <[email protected]>
  • Loading branch information
supercairos committed Mar 20, 2024
1 parent c23b342 commit 021a554
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
11 changes: 8 additions & 3 deletions pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,17 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
images := GetImagesFromImageList(app)

for _, c := range images {
helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c.ImageAlias)
imageName := c.ImageAlias
if c.ImageAlias == "" {
imageName = c.ImageName
}

helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, imageName)
if helmAnnotationParamName == "" {
return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageAlias)
return nil, fmt.Errorf("could not find an image-name annotation for image %s", imageName)
}
if helmAnnotationParamVersion == "" {
return nil, fmt.Errorf("could not find an image-tag annotation for image %s", c.ImageAlias)
return nil, fmt.Errorf("could not find an image-tag annotation for image %s", imageName)
}

helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
Expand Down
20 changes: 14 additions & 6 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,8 +1320,9 @@ helm:

t.Run("Valid Helm source with Helm values file", func(t *testing.T) {
expected := `
image.name: nginx
image.tag: v1.0.0
image:
name: nginx
tag: v1.0.0
replicas: 1
`
app := v1alpha1.Application{
Expand Down Expand Up @@ -1366,8 +1367,9 @@ replicas: 1
}

originalData := []byte(`
image.name: nginx
image.tag: v0.0.0
image:
name: nginx
tag: v0.0.0
replicas: 1
`)
yaml, err := marshalParamsOverride(&app, originalData)
Expand Down Expand Up @@ -1512,7 +1514,10 @@ replicas: 1
},
}

originalData := []byte(`random content`)
originalData := []byte(`
random:
content: hello
`)
_, err := marshalParamsOverride(&app, originalData)
assert.Error(t, err)
assert.Equal(t, "wrongimage.name parameter not found", err.Error())
Expand Down Expand Up @@ -1560,7 +1565,10 @@ replicas: 1
},
}

originalData := []byte(`random content`)
originalData := []byte(`
random:
content: hello
`)
_, err := marshalParamsOverride(&app, originalData)
assert.Error(t, err)
assert.Equal(t, "wrongimage.tag parameter not found", err.Error())
Expand Down

0 comments on commit 021a554

Please sign in to comment.