From 021a55482ff477ce5f2b366ffd132e1d8b86f8ee Mon Sep 17 00:00:00 2001 From: Romain Caire Date: Wed, 20 Mar 2024 18:53:53 +0100 Subject: [PATCH] Fix tests Signed-off-by: Romain Caire --- pkg/argocd/update.go | 11 ++++++++--- pkg/argocd/update_test.go | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index aba999b4..816f3fd0 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -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) diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 1d1246fa..199b4436 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -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{ @@ -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) @@ -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()) @@ -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())