Repository: xanzy/go-gitlab
Pull request #985 (2020-11-25 20:26:21)

Add recent_failures to test case
As of v13.6 there was a change to include recent failures data in test
reports response

Ref: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/45187


Patch:
diff --git a/pipelines.go b/pipelines.go
index 07427f9..4d2bd77 100644
--- a/pipelines.go
+++ b/pipelines.go
@@ -105,14 +105,21 @@ type PipelineTestSuites struct {
 
 // PipelineTestCases contains test cases details.
 type PipelineTestCases struct {
-	Status        string  `json:"status"`
-	Name          string  `json:"name"`
-	Classname     string  `json:"classname"`
-	File          string  `json:"file"`
-	ExecutionTime float64 `json:"execution_time"`
-	SystemOutput  string  `json:"system_output"`
-	StackTrace    string  `json:"stack_trace"`
-	AttachmentUrl string  `json:"attachment_url"`
+	Status         string         `json:"status"`
+	Name           string         `json:"name"`
+	Classname      string         `json:"classname"`
+	File           string         `json:"file"`
+	ExecutionTime  float64        `json:"execution_time"`
+	SystemOutput   string         `json:"system_output"`
+	StackTrace     string         `json:"stack_trace"`
+	AttachmentURL  string         `json:"attachment_url"`
+	RecentFailures RecentFailures `json:"recent_failures"`
+}
+
+// RecentFailures contains failures count for the project's default branch.
+type RecentFailures struct {
+	Count      int    `json:"count"`
+	BaseBranch string `json:"base_branch"`
 }
 
 func (p PipelineTestReport) String() string {


Test patch:
diff --git a/pipelines_test.go b/pipelines_test.go
index 91beb64..b249a63 100644
--- a/pipelines_test.go
+++ b/pipelines_test.go
@@ -107,18 +107,22 @@ func TestGetPipelineTestReport(t *testing.T) {
 						ExecutionTime: 19.987,
 						SystemOutput:  "output message\n\noutput message 2",
 						StackTrace:    "java.lang.Exception: Stack trace\nat java.base/java.lang.Thread.dumpStack(Thread.java:1383)",
-						AttachmentUrl: "http://foo.bar",
+						AttachmentURL: "http://foo.bar",
+						RecentFailures: RecentFailures{
+							Count:      10,
+							BaseBranch: "master",
+						},
 					},
-
 					{
-						Status:        "error",
-						Name:          "Error testcase 2",
-						Classname:     "MyClass",
-						File:          "",
-						ExecutionTime: 19.984,
-						SystemOutput:  "",
-						StackTrace:    "",
-						AttachmentUrl: "",
+						Status:         "error",
+						Name:           "Error testcase 2",
+						Classname:      "MyClass",
+						File:           "",
+						ExecutionTime:  19.984,
+						SystemOutput:   "",
+						StackTrace:     "",
+						AttachmentURL:  "",
+						RecentFailures: RecentFailures{},
 					},
 					{
 						Status:        "error",
@@ -128,7 +132,7 @@ func TestGetPipelineTestReport(t *testing.T) {
 						ExecutionTime: 0.0,
 						SystemOutput:  "Undefined message",
 						StackTrace:    "",
-						AttachmentUrl: "",
+						AttachmentURL: "",
 					},
 					{
 						Status:        "success",
@@ -138,7 +142,7 @@ func TestGetPipelineTestReport(t *testing.T) {
 						ExecutionTime: 19.7799999999999985,
 						SystemOutput:  "",
 						StackTrace:    "",
-						AttachmentUrl: "",
+						AttachmentURL: "",
 					}},
 			},
 			{
@@ -157,7 +161,7 @@ func TestGetPipelineTestReport(t *testing.T) {
 					ExecutionTime: 1.008,
 					SystemOutput:  "",
 					StackTrace:    "",
-					AttachmentUrl: "",
+					AttachmentURL: "",
 				}},
 			},
 		}}
diff --git a/testdata/get_pipeline_testreport.json b/testdata/get_pipeline_testreport.json
index 0a0f68a..f7a4fc2 100644
--- a/testdata/get_pipeline_testreport.json
+++ b/testdata/get_pipeline_testreport.json
@@ -24,7 +24,11 @@
                     "execution_time": 19.987,
                     "system_output": "output message\n\noutput message 2",
                     "stack_trace": "java.lang.Exception: Stack trace\nat java.base/java.lang.Thread.dumpStack(Thread.java:1383)",
-                    "attachment_url": "http://foo.bar"
+                    "attachment_url": "http://foo.bar",
+                    "recent_failures": {
+                        "count": 10,
+                        "base_branch": "master"
+                    }
                 },
                 {
                     "status": "error",
@@ -34,7 +38,8 @@
                     "execution_time": 19.984,
                     "system_output": null,
                     "stack_trace": null,
-                    "attachment_url": null
+                    "attachment_url": null,
+                    "recent_failures": null
                 },
                 {
                     "status": "error",