From 9caa3b42f108d5a38fe22bb6d3e76c51af1f5c46 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 5 Apr 2021 12:08:38 +0100 Subject: [PATCH] Test that an unchanged image is not in result With reference to https://github.com/fluxcd/image-automation-controller/issues/133 this commit adapts the update->result test so that it checks an additional case: that a field with an update marker that _does_ correspond to a policy, but _doesn't_ get changed, is not included in the results. This test fails at present, because the method for determining the result is to count which setters are referenced, rather than which fields were changed. Signed-off-by: Michael Bridgen --- .../testdata/setters/expected/marked.yaml | 2 + .../testdata/setters/original/marked.yaml | 2 + pkg/update/update_test.go | 43 ++++++++++++++----- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pkg/update/testdata/setters/expected/marked.yaml b/pkg/update/testdata/setters/expected/marked.yaml index 4efafc52..cc1e72e0 100644 --- a/pkg/update/testdata/setters/expected/marked.yaml +++ b/pkg/update/testdata/setters/expected/marked.yaml @@ -12,3 +12,5 @@ spec: containers: - name: c image: updated:v1.0.1 # {"$imagepolicy": "automation-ns:policy"} + - name: d + image: image:v1.0.0 # {"$imagepolicy": "automation-ns:unchanged"} diff --git a/pkg/update/testdata/setters/original/marked.yaml b/pkg/update/testdata/setters/original/marked.yaml index 4032f9c9..aa25c15a 100644 --- a/pkg/update/testdata/setters/original/marked.yaml +++ b/pkg/update/testdata/setters/original/marked.yaml @@ -12,3 +12,5 @@ spec: containers: - name: c image: image:v1.0.0 # {"$imagepolicy": "automation-ns:policy"} + - name: d + image: image:v1.0.0 # {"$imagepolicy": "automation-ns:unchanged"} diff --git a/pkg/update/update_test.go b/pkg/update/update_test.go index 4e42f7d7..297fe457 100644 --- a/pkg/update/update_test.go +++ b/pkg/update/update_test.go @@ -38,12 +38,9 @@ func TestUpdate(t *testing.T) { } var _ = Describe("Update image via kyaml setters2", func() { - It("updates the image marked with the image policy (setter) ref", func() { - tmp, err := ioutil.TempDir("", "gotest") - Expect(err).ToNot(HaveOccurred()) - defer os.RemoveAll(tmp) - policies := []imagev1alpha1_reflect.ImagePolicy{ + var ( + policies = []imagev1alpha1_reflect.ImagePolicy{ imagev1alpha1_reflect.ImagePolicy{ ObjectMeta: metav1.ObjectMeta{ // name matches marker used in testdata/setters/{original,expected} Namespace: "automation-ns", @@ -53,14 +50,19 @@ var _ = Describe("Update image via kyaml setters2", func() { LatestImage: "updated:v1.0.1", }, }, + imagev1alpha1_reflect.ImagePolicy{ + ObjectMeta: metav1.ObjectMeta{ // name matches marker used in testdata/setters/{original,expected} + Namespace: "automation-ns", + Name: "unchanged", + }, + Status: imagev1alpha1_reflect.ImagePolicyStatus{ + LatestImage: "image:v1.0.0", + }, + }, } + ) - _, err = UpdateWithSetters("testdata/setters/original", tmp, policies) - Expect(err).ToNot(HaveOccurred()) - test.ExpectMatchingDirectories(tmp, "testdata/setters/expected") - }) - - It("gives the result of the updates", func() { + It("updates the image marked with the image policy (setter) ref", func() { tmp, err := ioutil.TempDir("", "gotest") Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmp) @@ -75,8 +77,27 @@ var _ = Describe("Update image via kyaml setters2", func() { LatestImage: "updated:v1.0.1", }, }, + imagev1alpha1_reflect.ImagePolicy{ + ObjectMeta: metav1.ObjectMeta{ // name matches marker used in testdata/setters/{original,expected} + Namespace: "automation-ns", + Name: "unchanged", + }, + Status: imagev1alpha1_reflect.ImagePolicyStatus{ + LatestImage: "image:v1.0.0", + }, + }, } + _, err = UpdateWithSetters("testdata/setters/original", tmp, policies) + Expect(err).ToNot(HaveOccurred()) + test.ExpectMatchingDirectories(tmp, "testdata/setters/expected") + }) + + It("gives the result of the updates", func() { + tmp, err := ioutil.TempDir("", "gotest") + Expect(err).ToNot(HaveOccurred()) + defer os.RemoveAll(tmp) + result, err := UpdateWithSetters("testdata/setters/original", tmp, policies) Expect(err).ToNot(HaveOccurred())