Skip to content

Commit 748c474

Browse files
authored
Merge pull request #1588 from konflux-ci/agent/1578-gitlab-reporter-coverage
test(STONEINTG-1561): increase GitLab reporter coverage
2 parents 2b9ea39 + 1d2c687 commit 748c474

1 file changed

Lines changed: 68 additions & 8 deletions

File tree

status/reporter_gitlab_test.go

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,42 @@ var _ = Describe("GitLabReporter", func() {
208208
Entry("Missing source project ID", gitops.PipelineAsCodeSourceProjectIDAnnotation, false),
209209
)
210210

211+
It("returns error when pull-request annotation is missing for non-push event", func() {
212+
delete(hasSnapshot.Annotations, gitops.PipelineAsCodePullRequestAnnotation)
213+
// Add pull-request as a label so IsSnapshotCreatedByPACPushEvent returns false
214+
hasSnapshot.Labels[gitops.PipelineAsCodePullRequestAnnotation] = "45"
215+
statusCode, err := reporter.Initialize(context.TODO(), hasSnapshot)
216+
Expect(err).To(HaveOccurred())
217+
Expect(statusCode).To(Equal(0))
218+
Expect(err.Error()).To(ContainSubstring("pull-request annotation not found"))
219+
})
220+
221+
It("returns error when target project ID is not a valid integer", func() {
222+
hasSnapshot.Annotations[gitops.PipelineAsCodeTargetProjectIDAnnotation] = "not-a-number"
223+
statusCode, err := reporter.Initialize(context.TODO(), hasSnapshot)
224+
Expect(err).To(HaveOccurred())
225+
Expect(statusCode).To(Equal(0))
226+
Expect(err.Error()).To(ContainSubstring("failed to convert project ID"))
227+
})
228+
229+
It("returns error when source project ID is not a valid integer", func() {
230+
hasSnapshot.Annotations[gitops.PipelineAsCodeSourceProjectIDAnnotation] = "not-a-number"
231+
statusCode, err := reporter.Initialize(context.TODO(), hasSnapshot)
232+
Expect(err).To(HaveOccurred())
233+
Expect(statusCode).To(Equal(0))
234+
Expect(err.Error()).To(ContainSubstring("failed to convert project ID"))
235+
})
236+
237+
It("returns error when merge request number is not a valid integer for non-push event", func() {
238+
hasSnapshot.Annotations[gitops.PipelineAsCodePullRequestAnnotation] = "not-a-number"
239+
// Add pull-request as a label so IsSnapshotCreatedByPACPushEvent returns false
240+
hasSnapshot.Labels[gitops.PipelineAsCodePullRequestAnnotation] = "not-a-number"
241+
statusCode, err := reporter.Initialize(context.TODO(), hasSnapshot)
242+
Expect(err).To(HaveOccurred())
243+
Expect(statusCode).To(Equal(0))
244+
Expect(err.Error()).To(ContainSubstring("failed to convert merge request number"))
245+
})
246+
211247
It("creates a commit status for snapshot with correct textual data", func() {
212248

213249
summary := "Integration test for component component-sample snapshot snapshot-sample and scenario scenario1 failed"
@@ -596,15 +632,39 @@ var _ = Describe("GitLabReporter", func() {
596632
Expect(err).ToNot(HaveOccurred())
597633
}
598634
})
599-
It("check if optional integration test returns skipped status for failed test", func() {
600-
state, err := status.GenerateGitlabCommitState(integrationteststatus.IntegrationTestStatusTestFail, true)
601-
Expect(err).NotTo(HaveOccurred())
602-
Expect(state).To(Equal(gitlab.Skipped))
635+
DescribeTable(
636+
"reports correct gitlab statuses from test statuses for optional scenarios",
637+
func(teststatus integrationteststatus.IntegrationTestStatus, glState gitlab.BuildStateValue) {
638+
639+
state, err := status.GenerateGitlabCommitState(teststatus, true)
640+
Expect(err).ToNot(HaveOccurred())
641+
Expect(state).To(Equal(glState))
642+
},
643+
Entry("Pending (optional)", integrationteststatus.IntegrationTestStatusPending, gitlab.Pending),
644+
Entry("BuildPLRInProgress (optional)", integrationteststatus.BuildPLRInProgress, gitlab.Pending),
645+
Entry("In progress (optional)", integrationteststatus.IntegrationTestStatusInProgress, gitlab.Pending),
646+
Entry("Provision error (optional)", integrationteststatus.IntegrationTestStatusEnvironmentProvisionError_Deprecated, gitlab.Skipped),
647+
Entry("Deployment error (optional)", integrationteststatus.IntegrationTestStatusDeploymentError_Deprecated, gitlab.Skipped),
648+
Entry("Test failure (optional)", integrationteststatus.IntegrationTestStatusTestFail, gitlab.Skipped),
649+
Entry("Invalid (optional)", integrationteststatus.IntegrationTestStatusTestInvalid, gitlab.Skipped),
650+
Entry("Deleted (optional)", integrationteststatus.IntegrationTestStatusDeleted, gitlab.Canceled),
651+
Entry("BuildPLRFailed (optional)", integrationteststatus.BuildPLRFailed, gitlab.Canceled),
652+
Entry("SnapshotCreationFailed (optional)", integrationteststatus.SnapshotCreationFailed, gitlab.Canceled),
653+
Entry("GroupSnapshotCreationFailed (optional)", integrationteststatus.GroupSnapshotCreationFailed, gitlab.Canceled),
654+
Entry("Success (optional)", integrationteststatus.IntegrationTestStatusTestPassed, gitlab.Success),
655+
Entry("Warning (optional)", integrationteststatus.IntegrationTestStatusTestWarning, gitlab.Success),
656+
)
657+
658+
It("returns error for unknown status (non-optional)", func() {
659+
_, err := status.GenerateGitlabCommitState(integrationteststatus.IntegrationTestStatus(-1), false)
660+
Expect(err).To(HaveOccurred())
661+
Expect(err.Error()).To(ContainSubstring("unknown status"))
603662
})
604-
It("check if optional integration test returns skipped status for invalid test", func() {
605-
state, err := status.GenerateGitlabCommitState(integrationteststatus.IntegrationTestStatusTestInvalid, true)
606-
Expect(err).NotTo(HaveOccurred())
607-
Expect(state).To(Equal(gitlab.Skipped))
663+
664+
It("returns error for unknown status (optional)", func() {
665+
_, err := status.GenerateGitlabCommitState(integrationteststatus.IntegrationTestStatus(-1), true)
666+
Expect(err).To(HaveOccurred())
667+
Expect(err.Error()).To(ContainSubstring("unknown status"))
608668
})
609669
})
610670
})

0 commit comments

Comments
 (0)