From 9a8e210df8edca2178db3cb0e158f35da6765869 Mon Sep 17 00:00:00 2001 From: crabique Date: Mon, 10 Mar 2025 17:24:20 +0200 Subject: [PATCH] add tests for kustomize config name handling Signed-off-by: crabique --- pkg/update/filereader_test.go | 16 ++++++------ .../testdata/setters/expected/Kustomization | 9 +++++++ .../{kustomization.yaml => kustomization.yml} | 0 .../testdata/setters/original/Kustomization | 9 +++++++ .../{kustomization.yaml => kustomization.yml} | 0 pkg/update/update_test.go | 25 +++++++++++++++++-- 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 pkg/update/testdata/setters/expected/Kustomization rename pkg/update/testdata/setters/expected/{kustomization.yaml => kustomization.yml} (100%) create mode 100644 pkg/update/testdata/setters/original/Kustomization rename pkg/update/testdata/setters/original/{kustomization.yaml => kustomization.yml} (100%) diff --git a/pkg/update/filereader_test.go b/pkg/update/filereader_test.go index 8df6c588..daaa65b0 100644 --- a/pkg/update/filereader_test.go +++ b/pkg/update/filereader_test.go @@ -33,11 +33,12 @@ func TestScreeningLocalReader(t *testing.T) { } nodes, err := r.Read() g.Expect(err).ToNot(HaveOccurred()) - // the test fixture has three files that contain the marker: - // - otherns.yaml + // the test fixture has four files that contain the marker: // - marked.yaml - // - kustomization.yaml - g.Expect(len(nodes)).To(Equal(3)) + // - otherns.yaml + // - kustomization.yml + // - Kustomization + g.Expect(len(nodes)).To(Equal(4)) filesSeen := map[string]struct{}{} for i := range nodes { path, _, err := kioutil.GetFileAnnotations(nodes[i]) @@ -45,9 +46,10 @@ func TestScreeningLocalReader(t *testing.T) { filesSeen[path] = struct{}{} } g.Expect(filesSeen).To(Equal(map[string]struct{}{ - "marked.yaml": {}, - "kustomization.yaml": {}, - "otherns.yaml": {}, + "marked.yaml": {}, + "otherns.yaml": {}, + "kustomization.yml": {}, + "Kustomization": {}, })) } diff --git a/pkg/update/testdata/setters/expected/Kustomization b/pkg/update/testdata/setters/expected/Kustomization new file mode 100644 index 00000000..6235fec8 --- /dev/null +++ b/pkg/update/testdata/setters/expected/Kustomization @@ -0,0 +1,9 @@ +# This is not intended to be a working kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - irrelevant.yaml +images: + - name: container + newName: index.repo.fake/updated # {"$imagepolicy": "automation-ns:policy:name"} + newTag: v1.0.1 # {"$imagepolicy": "automation-ns:policy:tag"} diff --git a/pkg/update/testdata/setters/expected/kustomization.yaml b/pkg/update/testdata/setters/expected/kustomization.yml similarity index 100% rename from pkg/update/testdata/setters/expected/kustomization.yaml rename to pkg/update/testdata/setters/expected/kustomization.yml diff --git a/pkg/update/testdata/setters/original/Kustomization b/pkg/update/testdata/setters/original/Kustomization new file mode 100644 index 00000000..155b73ab --- /dev/null +++ b/pkg/update/testdata/setters/original/Kustomization @@ -0,0 +1,9 @@ +# This is not intended to be a working kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - irrelevant.yaml +images: + - name: container + newName: replaced # {"$imagepolicy": "automation-ns:policy:name"} + newTag: v1 # {"$imagepolicy": "automation-ns:policy:tag"} diff --git a/pkg/update/testdata/setters/original/kustomization.yaml b/pkg/update/testdata/setters/original/kustomization.yml similarity index 100% rename from pkg/update/testdata/setters/original/kustomization.yaml rename to pkg/update/testdata/setters/original/kustomization.yml diff --git a/pkg/update/update_test.go b/pkg/update/update_test.go index 15c73a95..36f428b2 100644 --- a/pkg/update/update_test.go +++ b/pkg/update/update_test.go @@ -83,7 +83,14 @@ func TestUpdateWithSetters(t *testing.T) { expectedResult := Result{ Files: map[string]FileResult{ - "kustomization.yaml": { + "kustomization.yml": { + Objects: map[ObjectIdentifier][]ImageRef{ + kustomizeResourceID: { + expectedImageRef, + }, + }, + }, + "Kustomization": { Objects: map[ObjectIdentifier][]ImageRef{ kustomizeResourceID: { expectedImageRef, @@ -111,7 +118,21 @@ func TestUpdateWithSetters(t *testing.T) { expectedResultV2 := ResultV2{ ImageResult: expectedResult, FileChanges: map[string]ObjectChanges{ - "kustomization.yaml": { + "kustomization.yml": { + kustomizeResourceID: []Change{ + { + OldValue: "replaced", + NewValue: "index.repo.fake/updated", + Setter: "automation-ns:policy:name", + }, + { + OldValue: "v1", + NewValue: "v1.0.1", + Setter: "automation-ns:policy:tag", + }, + }, + }, + "Kustomization": { kustomizeResourceID: []Change{ { OldValue: "replaced",