@@ -71,8 +71,10 @@ func HasSummary(value string) gomock.Matcher {
7171}
7272
7373func newIntegrationTestStatusDetail (expectedScenarioStatus integrationteststatus.IntegrationTestStatus , isOptionalScenario bool ) integrationteststatus.IntegrationTestStatusDetail {
74- ts , _ := time .Parse (time .RFC3339 , "2023-07-26T16:57:49+02:00" )
75- tc , _ := time .Parse (time .RFC3339 , "2023-07-26T17:57:49+02:00" )
74+ ts , err := time .Parse (time .RFC3339 , "2023-07-26T16:57:49+02:00" )
75+ Expect (err ).NotTo (HaveOccurred ())
76+ tc , err := time .Parse (time .RFC3339 , "2023-07-26T17:57:49+02:00" )
77+ Expect (err ).NotTo (HaveOccurred ())
7678 return integrationteststatus.IntegrationTestStatusDetail {
7779 ScenarioName : "scenario1" ,
7880 Status : expectedScenarioStatus ,
@@ -85,6 +87,23 @@ func newIntegrationTestStatusDetail(expectedScenarioStatus integrationteststatus
8587 }
8688}
8789
90+ func newIntegrationTestStatusDetailWarning (expectedScenarioStatus integrationteststatus.IntegrationTestStatus , isOptionalScenario bool ) integrationteststatus.IntegrationTestStatusDetail {
91+ ts , err := time .Parse (time .RFC3339 , "2023-07-26T16:57:49+02:00" )
92+ Expect (err ).NotTo (HaveOccurred ())
93+ tc , err := time .Parse (time .RFC3339 , "2023-07-26T17:57:49+02:00" )
94+ Expect (err ).NotTo (HaveOccurred ())
95+ return integrationteststatus.IntegrationTestStatusDetail {
96+ ScenarioName : "scenario2" ,
97+ Status : expectedScenarioStatus ,
98+ LastUpdateTime : time .Now ().UTC (),
99+ Details : "warning" ,
100+ StartTime : & ts ,
101+ CompletionTime : & tc ,
102+ TestPipelineRunName : "test-pipelinerun-warning" ,
103+ IsOptionalScenario : isOptionalScenario ,
104+ }
105+ }
106+
88107// muxMergeRequestGet mocks a GET request for a specific Merge Request.
89108// It returns a MergeRequest object with the specified state.
90109func muxMergeRequestGet (mux * http.ServeMux , pid , mrIID int , state string ) {
@@ -122,9 +141,11 @@ var _ = Describe("Status Adapter", func() {
122141 mockReporter * status.MockReporterInterface
123142
124143 pipelineRun * tektonv1.PipelineRun
144+ pipelineRunWarn * tektonv1.PipelineRun
125145 successfulTaskRun * tektonv1.TaskRun
126146 failedTaskRun * tektonv1.TaskRun
127147 skippedTaskRun * tektonv1.TaskRun
148+ warningTaskRun * tektonv1.TaskRun
128149 mockK8sClient * MockK8sClient
129150 repo pacv1alpha1.Repository
130151
@@ -272,6 +293,49 @@ var _ = Describe("Status Adapter", func() {
272293 },
273294 }
274295
296+ warningTaskRun = & tektonv1.TaskRun {
297+ ObjectMeta : metav1.ObjectMeta {
298+ Name : "test-taskrun-warning" ,
299+ Namespace : "default" ,
300+ },
301+ Spec : tektonv1.TaskRunSpec {
302+ TaskRef : & tektonv1.TaskRef {
303+ Name : "test-taskrun-warning" ,
304+ ResolverRef : tektonv1.ResolverRef {
305+ Resolver : "bundle" ,
306+ Params : tektonv1.Params {
307+ {
308+ Name : "bundle" ,
309+ Value : tektonv1.ParamValue {Type : "string" , StringVal : "quay.io/redhat-appstudio/example-tekton-bundle:test" },
310+ },
311+ {
312+ Name : "name" ,
313+ Value : tektonv1.ParamValue {Type : "string" , StringVal : "test-task" },
314+ },
315+ },
316+ },
317+ },
318+ },
319+ Status : tektonv1.TaskRunStatus {
320+ TaskRunStatusFields : tektonv1.TaskRunStatusFields {
321+ StartTime : & metav1.Time {Time : now },
322+ CompletionTime : & metav1.Time {Time : now .Add (5 * time .Minute )},
323+ Results : []tektonv1.TaskRunResult {
324+ {
325+ Name : "TEST_OUTPUT" ,
326+ Value : * tektonv1 .NewStructuredValues (`{
327+ "result": "WARNING",
328+ "timestamp": "2024-05-22T06:42:21+00:00",
329+ "failures": 0,
330+ "successes": 10,
331+ "warnings": 1
332+ }` ),
333+ },
334+ },
335+ },
336+ },
337+ }
338+
275339 pipelineRun = & tektonv1.PipelineRun {
276340 ObjectMeta : metav1.ObjectMeta {
277341 Name : "test-pipelinerun" ,
@@ -306,6 +370,37 @@ var _ = Describe("Status Adapter", func() {
306370 },
307371 }
308372
373+ pipelineRunWarn = & tektonv1.PipelineRun {
374+ ObjectMeta : metav1.ObjectMeta {
375+ Name : "test-pipelinerun-warning" ,
376+ Namespace : "default" ,
377+ Labels : map [string ]string {
378+ "appstudio.openshift.io/component" : "devfile-sample-go-basic" ,
379+ "test.appstudio.openshift.io/scenario" : "example-pass" ,
380+ "pac.test.appstudio.openshift.io/git-provider" : "github" ,
381+ "pac.test.appstudio.openshift.io/url-org" : "devfile-sample" ,
382+ "pac.test.appstudio.openshift.io/url-repository" : "devfile-sample-go-basic" ,
383+ "pac.test.appstudio.openshift.io/sha" : "12a4a35ccd08194595179815e4646c3a6c08bb77" ,
384+ "pac.test.appstudio.openshift.io/event-type" : "pull_request" ,
385+ },
386+ Annotations : map [string ]string {
387+ "pac.test.appstudio.openshift.io/repo-url" : "https://github.com/devfile-sample/devfile-sample-go-basic" ,
388+ },
389+ },
390+ Status : tektonv1.PipelineRunStatus {
391+
392+ PipelineRunStatusFields : tektonv1.PipelineRunStatusFields {
393+ StartTime : & metav1.Time {Time : time .Now ()},
394+ ChildReferences : []tektonv1.ChildStatusReference {
395+ {
396+ Name : warningTaskRun .Name ,
397+ PipelineTaskName : "pipeline2-task1" ,
398+ },
399+ },
400+ },
401+ },
402+ }
403+
309404 hasSnapshot = & applicationapiv1alpha1.Snapshot {
310405 ObjectMeta : metav1.ObjectMeta {
311406 Name : "snapshot-sample" ,
@@ -483,11 +578,15 @@ var _ = Describe("Status Adapter", func() {
483578 taskRun .Status = failedTaskRun .Status
484579 case skippedTaskRun .Name :
485580 taskRun .Status = skippedTaskRun .Status
581+ case warningTaskRun .Name :
582+ taskRun .Status = warningTaskRun .Status
486583 }
487584 }
488585 if plr , ok := obj .(* tektonv1.PipelineRun ); ok {
489586 if key .Name == pipelineRun .Name {
490587 plr .Status = pipelineRun .Status
588+ } else if key .Name == pipelineRunWarn .Name {
589+ plr .Status = pipelineRunWarn .Status
491590 }
492591 }
493592 if snapshot , ok := obj .(* applicationapiv1alpha1.Snapshot ); ok {
@@ -637,6 +736,45 @@ var _ = Describe("Status Adapter", func() {
637736 Expect (testReport ).To (Equal (& expectedTestReport ))
638737 })
639738
739+ It ("report status for Warning test scenario" , func () {
740+ hasSnapshot .Annotations ["test.appstudio.openshift.io/status" ] = "[{\" scenario\" :\" scenario2\" ,\" status\" :\" Warning\" ,\" testPipelineRunName\" :\" test-pipelinerun-warning\" ,\" startTime\" :\" 2023-07-26T16:57:49+02:00\" ,\" completionTime\" :\" 2023-07-26T17:57:49+02:00\" ,\" lastUpdateTime\" :\" 2023-08-26T17:57:55+02:00\" ,\" details\" :\" failed\" }]"
741+ integrationTestStatusDetail := newIntegrationTestStatusDetailWarning (integrationteststatus .IntegrationTestStatusTestWarning , false )
742+ Expect (integrationTestStatusDetail .IsOptionalScenario ).To (BeFalse ())
743+ delete (hasSnapshot .Labels , "appstudio.openshift.io/component" )
744+ ts , err := time .Parse (time .RFC3339 , "2023-07-26T16:57:49+02:00" )
745+ Expect (err ).NotTo (HaveOccurred ())
746+ tc , err := time .Parse (time .RFC3339 , "2023-07-26T17:57:49+02:00" )
747+ Expect (err ).NotTo (HaveOccurred ())
748+ text := `<ul>
749+ <li><b>Pipelinerun</b>: <a href="https://definetly.not.prod/preview/application-pipeline/ns/default/pipelinerun/test-pipelinerun-warning">test-pipelinerun-warning</a></li>
750+ </ul>
751+ <hr>
752+
753+ | Task | Duration | Test Suite | Status | Details |
754+ | --- | --- | --- | --- | --- |
755+ | <a href="https://definetly.not.prod/preview/application-pipeline/ns/default/pipelinerun/test-pipelinerun-warning/logs/pipeline2-task1">pipeline2-task1</a> | 5m0s | | :warning: WARNING | :heavy_check_mark: 10 success(es)<br>:warning: 1 warning(s) |
756+
757+
758+ `
759+ expectedTestReport := status.TestReport {
760+ FullName : "Red Hat Konflux / scenario2 / component-sample" ,
761+ ScenarioName : "scenario2" ,
762+ SnapshotName : "snapshot-sample" ,
763+ ComponentName : "component-sample" ,
764+ Text : text ,
765+ ShortText : "<ul>\n <li><b>Pipelinerun</b>: <a href=\" https://definetly.not.prod/preview/application-pipeline/ns/default/pipelinerun/test-pipelinerun-warning\" >test-pipelinerun-warning</a></li>\n </ul>\n \n " ,
766+ Summary : "Integration test for component component-sample snapshot snapshot-sample and scenario scenario2 has warning(s)" ,
767+ Status : integrationteststatus .IntegrationTestStatusTestWarning ,
768+ StartTime : & ts ,
769+ CompletionTime : & tc ,
770+ TestPipelineRunName : "test-pipelinerun-warning" ,
771+ }
772+
773+ testReport , err := status .GenerateTestReport (context .Background (), mockK8sClient , integrationTestStatusDetail , hasSnapshot , "component-sample" )
774+ Expect (err ).NotTo (HaveOccurred ())
775+ Expect (testReport ).To (Equal (& expectedTestReport ))
776+ })
777+
640778 It ("report status for optional TestPassed test scenario" , func () {
641779 hasSnapshot .Annotations ["test.appstudio.openshift.io/status" ] = "[{\" scenario\" :\" scenario1\" ,\" status\" :\" TestPassed\" ,\" testPipelineRunName\" :\" test-pipelinerun\" ,\" startTime\" :\" 2023-07-26T16:57:49+02:00\" ,\" completionTime\" :\" 2023-07-26T17:57:49+02:00\" ,\" lastUpdateTime\" :\" 2023-08-26T17:57:55+02:00\" ,\" details\" :\" failed\" , \" isOptionalScenario\" :\" true\" }]"
642780 integrationTestStatusDetail := newIntegrationTestStatusDetail (integrationteststatus .IntegrationTestStatusTestPassed , true )
0 commit comments