Skip to content

Commit

Permalink
Test that an unchanged image is not in result
Browse files Browse the repository at this point in the history
With reference to

    #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 <michael@weave.works>
  • Loading branch information
squaremo committed Apr 5, 2021
1 parent 8478fd9 commit 5421d55
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkg/update/testdata/setters/expected/marked.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
2 changes: 2 additions & 0 deletions pkg/update/testdata/setters/original/marked.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
43 changes: 32 additions & 11 deletions pkg/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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())

Expand Down

0 comments on commit 5421d55

Please sign in to comment.