From 3f078c2d4136009dc25c9a567b895a15e3d16b4b Mon Sep 17 00:00:00 2001 From: Jing Qi Date: Thu, 7 Sep 2023 15:08:42 +0800 Subject: [PATCH] fix(STONTEINTG-573): fix confusing message about failed test Signed-off-by: Jing Qi Update the log message when there are no integration tests --- gitops/snapshot.go | 25 +++++++++++++++---------- gitops/snapshot_test.go | 7 +++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gitops/snapshot.go b/gitops/snapshot.go index 02fb74f06..2c538858b 100644 --- a/gitops/snapshot.go +++ b/gitops/snapshot.go @@ -333,17 +333,22 @@ func HaveAppStudioTestsSucceeded(snapshot *applicationapiv1alpha1.Snapshot) bool func CanSnapshotBePromoted(snapshot *applicationapiv1alpha1.Snapshot) (bool, []string) { canBePromoted := true reasons := make([]string, 0) - if !HaveAppStudioTestsSucceeded(snapshot) { + if !HaveAppStudioTestsFinished(snapshot) { canBePromoted = false - reasons = append(reasons, "the Snapshot hasn't passed all required integration tests") - } - if !IsSnapshotValid(snapshot) { - canBePromoted = false - reasons = append(reasons, "the Snapshot is invalid") - } - if IsSnapshotCreatedByPACPullRequestEvent(snapshot) { - canBePromoted = false - reasons = append(reasons, "the Snapshot was created for a PaC pull request event") + reasons = append(reasons, "the Snapshot has not yet finished testing") + } else { + if !HaveAppStudioTestsSucceeded(snapshot) { + canBePromoted = false + reasons = append(reasons, "the Snapshot hasn't passed all required integration tests") + } + if !IsSnapshotValid(snapshot) { + canBePromoted = false + reasons = append(reasons, "the Snapshot is invalid") + } + if IsSnapshotCreatedByPACPullRequestEvent(snapshot) { + canBePromoted = false + reasons = append(reasons, "the Snapshot was created for a PaC pull request event") + } } return canBePromoted, reasons } diff --git a/gitops/snapshot_test.go b/gitops/snapshot_test.go index cce78bb27..699824258 100644 --- a/gitops/snapshot_test.go +++ b/gitops/snapshot_test.go @@ -113,6 +113,13 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() { Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) }) + It("ensures the a decision can be made to NOT promote when the snaphot has not been marked as passed/failed", func() { + canBePromoted, reasons := gitops.CanSnapshotBePromoted(hasSnapshot) + Expect(canBePromoted).To(BeFalse()) + Expect(reasons).To(HaveLen(1)) + Expect(reasons[0]).To(Equal("the Snapshot has not yet finished testing")) + }) + It("ensures the Snapshots status can be marked as passed", func() { updatedSnapshot, err := gitops.MarkSnapshotAsPassed(k8sClient, ctx, hasSnapshot, "Test message") Expect(err).To(BeNil())