Skip to content

Commit

Permalink
add tests to check object's status message
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Sep 18, 2023
1 parent 73466b6 commit db8a257
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/controller/imageupdateautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
return failWithError(err)
}
log.Info("pushed commit to origin", "revision", rev, "branch", pushBranch)
statusMessage.WriteString(fmt.Sprintf("commited and pushed commit '%s' to branch '%s'", rev, pushBranch))
statusMessage.WriteString(fmt.Sprintf("committed and pushed commit '%s' to branch '%s'", rev, pushBranch))
}

if gitSpec.Push != nil && gitSpec.Push.Refspec != "" {
Expand Down
24 changes: 23 additions & 1 deletion internal/controller/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestImageAutomationReconciler_commitMessage(t *testing.T) {
updateStrategy := &imagev1.UpdateStrategy{
Strategy: imagev1.UpdateStrategySetters,
}
err := createImageUpdateAutomation(testEnv, "update-test", s.namespace, s.gitRepoName, s.gitRepoNamespace, s.branch, "", "", testCommitTemplate, "", updateStrategy)
err := createImageUpdateAutomation(testEnv, "update-test", s.namespace, s.gitRepoName, s.gitRepoNamespace, s.branch, s.branch, "", testCommitTemplate, "", updateStrategy)
g.Expect(err).ToNot(HaveOccurred())

// Wait for a new commit to be made by the controller.
Expand All @@ -225,6 +225,17 @@ func TestImageAutomationReconciler_commitMessage(t *testing.T) {
g.Expect(signature).NotTo(BeNil())
g.Expect(signature.Name).To(Equal(testAuthorName))
g.Expect(signature.Email).To(Equal(testAuthorEmail))

// Regression check to ensure the status message contains the branch name
// if checkout branch is the same as push branch.
imageUpdateKey := types.NamespacedName{
Namespace: s.namespace,
Name: "update-test",
}
var imageUpdate imagev1.ImageUpdateAutomation
_ = testEnv.Get(context.TODO(), imageUpdateKey, &imageUpdate)
ready := apimeta.FindStatusCondition(imageUpdate.Status.Conditions, meta.ReadyCondition)
g.Expect(ready.Message).To(Equal(fmt.Sprintf("committed and pushed commit '%s' to branch '%s'", head.Hash().String(), s.branch)))
},
)
})
Expand Down Expand Up @@ -517,6 +528,17 @@ func TestImageAutomationReconciler_push_refspec(t *testing.T) {
refspecHash := getRemoteRef(g, repoURL, "smth/else")
g.Expect(pushBranchHash.String()).ToNot(Equal(preChangeCommitId))
g.Expect(pushBranchHash.String()).To(Equal(refspecHash.String()))

imageUpdateKey := types.NamespacedName{
Namespace: s.namespace,
Name: "push-refspec",
}
var imageUpdate imagev1.ImageUpdateAutomation
_ = testEnv.Get(context.TODO(), imageUpdateKey, &imageUpdate)
ready := apimeta.FindStatusCondition(imageUpdate.Status.Conditions, meta.ReadyCondition)
g.Expect(ready.Message).To(Equal(
fmt.Sprintf("committed and pushed commit '%s' to branch '%s' and using refspec '%s'",
pushBranchHash.String(), pushBranch, refspec)))
},
)
})
Expand Down

0 comments on commit db8a257

Please sign in to comment.