Skip to content

Commit db8a257

Browse files
committed
add tests to check object's status message
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 73466b6 commit db8a257

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

internal/controller/imageupdateautomation_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
422422
return failWithError(err)
423423
}
424424
log.Info("pushed commit to origin", "revision", rev, "branch", pushBranch)
425-
statusMessage.WriteString(fmt.Sprintf("commited and pushed commit '%s' to branch '%s'", rev, pushBranch))
425+
statusMessage.WriteString(fmt.Sprintf("committed and pushed commit '%s' to branch '%s'", rev, pushBranch))
426426
}
427427

428428
if gitSpec.Push != nil && gitSpec.Push.Refspec != "" {

internal/controller/update_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func TestImageAutomationReconciler_commitMessage(t *testing.T) {
210210
updateStrategy := &imagev1.UpdateStrategy{
211211
Strategy: imagev1.UpdateStrategySetters,
212212
}
213-
err := createImageUpdateAutomation(testEnv, "update-test", s.namespace, s.gitRepoName, s.gitRepoNamespace, s.branch, "", "", testCommitTemplate, "", updateStrategy)
213+
err := createImageUpdateAutomation(testEnv, "update-test", s.namespace, s.gitRepoName, s.gitRepoNamespace, s.branch, s.branch, "", testCommitTemplate, "", updateStrategy)
214214
g.Expect(err).ToNot(HaveOccurred())
215215

216216
// Wait for a new commit to be made by the controller.
@@ -225,6 +225,17 @@ func TestImageAutomationReconciler_commitMessage(t *testing.T) {
225225
g.Expect(signature).NotTo(BeNil())
226226
g.Expect(signature.Name).To(Equal(testAuthorName))
227227
g.Expect(signature.Email).To(Equal(testAuthorEmail))
228+
229+
// Regression check to ensure the status message contains the branch name
230+
// if checkout branch is the same as push branch.
231+
imageUpdateKey := types.NamespacedName{
232+
Namespace: s.namespace,
233+
Name: "update-test",
234+
}
235+
var imageUpdate imagev1.ImageUpdateAutomation
236+
_ = testEnv.Get(context.TODO(), imageUpdateKey, &imageUpdate)
237+
ready := apimeta.FindStatusCondition(imageUpdate.Status.Conditions, meta.ReadyCondition)
238+
g.Expect(ready.Message).To(Equal(fmt.Sprintf("committed and pushed commit '%s' to branch '%s'", head.Hash().String(), s.branch)))
228239
},
229240
)
230241
})
@@ -517,6 +528,17 @@ func TestImageAutomationReconciler_push_refspec(t *testing.T) {
517528
refspecHash := getRemoteRef(g, repoURL, "smth/else")
518529
g.Expect(pushBranchHash.String()).ToNot(Equal(preChangeCommitId))
519530
g.Expect(pushBranchHash.String()).To(Equal(refspecHash.String()))
531+
532+
imageUpdateKey := types.NamespacedName{
533+
Namespace: s.namespace,
534+
Name: "push-refspec",
535+
}
536+
var imageUpdate imagev1.ImageUpdateAutomation
537+
_ = testEnv.Get(context.TODO(), imageUpdateKey, &imageUpdate)
538+
ready := apimeta.FindStatusCondition(imageUpdate.Status.Conditions, meta.ReadyCondition)
539+
g.Expect(ready.Message).To(Equal(
540+
fmt.Sprintf("committed and pushed commit '%s' to branch '%s' and using refspec '%s'",
541+
pushBranchHash.String(), pushBranch, refspec)))
520542
},
521543
)
522544
})

0 commit comments

Comments
 (0)