Skip to content

Commit

Permalink
update_test: Create ImagePolicy per subtest
Browse files Browse the repository at this point in the history
In TestImageUpdateAutomation_e2e, move the ImagePolicy to be created per
subtest and not shared in the common test environment. This makes the
tests more independent of each other.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Nov 11, 2021
1 parent dd81020 commit 9a23ef8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ spec:
spec:
containers:
- name: hello
image: helloworld:v1.3.1 # SETTER_SITE
image: helloworld:1.0.1 # SETTER_SITE
38 changes: 32 additions & 6 deletions controllers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,20 @@ func TestImageUpdateAutomation_e2e(t *testing.T) {
Name: imagePolicyName,
Namespace: namespace,
}
// NB not testing the image reflector controller; this
// will make a "fully formed" ImagePolicy object.
err = createImagePolicyWithLatestImage(imagePolicyName, namespace, "not-expected-to-exist", "1.x", latestImage)
g.Expect(err).ToNot(HaveOccurred(), "failed to create ImagePolicy resource")

// Create ImageUpdateAutomation resource for each of the test cases
// and cleanup at the end.
// Create ImagePolicy and ImageUpdateAutomation resource for each of the
// test cases and cleanup at the end.

t.Run("PushSpec", func(t *testing.T) {
// NB not testing the image reflector controller; this
// will make a "fully formed" ImagePolicy object.
err = createImagePolicyWithLatestImage(imagePolicyName, namespace, "not-expected-to-exist", "1.x", latestImage)
g.Expect(err).ToNot(HaveOccurred(), "failed to create ImagePolicy resource")

defer func() {
g.Expect(deleteImagePolicy(imagePolicyName, namespace)).ToNot(HaveOccurred())
}()

imageUpdateAutomationName := "update-" + randStringRunes(5)
pushBranch := "pr-" + randStringRunes(5)

Expand Down Expand Up @@ -435,6 +440,13 @@ func TestImageUpdateAutomation_e2e(t *testing.T) {
})

t.Run("with update strategy setters", func(t *testing.T) {
err = createImagePolicyWithLatestImage(imagePolicyName, namespace, "not-expected-to-exist", "1.x", latestImage)
g.Expect(err).ToNot(HaveOccurred(), "failed to create ImagePolicy resource")

defer func() {
g.Expect(deleteImagePolicy(imagePolicyName, namespace)).ToNot(HaveOccurred())
}()

// Insert a setter reference into the deployment file,
// before creating the automation object itself.
commitInRepo(g, cloneLocalRepoURL, branch, "Install setter marker", func(tmp string) {
Expand Down Expand Up @@ -477,6 +489,13 @@ func TestImageUpdateAutomation_e2e(t *testing.T) {
})

t.Run("no reconciliation when object is suspended", func(t *testing.T) {
err = createImagePolicyWithLatestImage(imagePolicyName, namespace, "not-expected-to-exist", "1.x", latestImage)
g.Expect(err).ToNot(HaveOccurred(), "failed to create ImagePolicy resource")

defer func() {
g.Expect(deleteImagePolicy(imagePolicyName, namespace)).ToNot(HaveOccurred())
}()

// Create the automation object.
updateKey := types.NamespacedName{
Namespace: namespace,
Expand Down Expand Up @@ -1046,6 +1065,13 @@ func deleteImageUpdateAutomation(name, namespace string) error {
return testEnv.Delete(context.Background(), update)
}

func deleteImagePolicy(name, namespace string) error {
imagePolicy := &imagev1_reflect.ImagePolicy{}
imagePolicy.Name = name
imagePolicy.Namespace = namespace
return testEnv.Delete(context.Background(), imagePolicy)
}

func createSigningKeyPair(name, namespace string) (*openpgp.Entity, error) {
pgpEntity, err := openpgp.NewEntity("", "", "", nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/update/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func mustRef(ref string) imageRef {
return imageRef{r, types.NamespacedName{}}
}

func TestMustRef(t *testing.T) {
func TestImageRef(t *testing.T) {
g := NewWithT(t)

t.Run("gives each component of an image ref", func(t *testing.T) {
Expand Down

0 comments on commit 9a23ef8

Please sign in to comment.