55 "strings"
66
77 "github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/testreport"
8- "github.com/pkg/errors"
8+ errorPkg "github.com/pkg/errors"
99)
1010
1111func (c * Converter ) Setup (_ bool ) {}
@@ -54,13 +54,9 @@ func parseTestReport(result resultReader) (TestReport, error) {
5454 return TestReport {TestSuites : []TestSuite {testSuite }}, nil
5555 }
5656
57- return TestReport {}, errors .Wrap (errors .Wrap (testSuiteErr , string (data )), testReportErr .Error ())
57+ return TestReport {}, errorPkg .Wrap (errorPkg .Wrap (testSuiteErr , string (data )), testReportErr .Error ())
5858}
5959
60- // merges Suites->Cases->Error and Suites->Cases->SystemErr field values into Suites->Cases->Failure field
61- // with 2 newlines and error category prefix
62- // the two newlines applied only if there is a failure message already
63- // this is required because our testing service currently handles failure field properly
6460func convertTestReport (report TestReport ) testreport.TestReport {
6561 convertedReport := testreport.TestReport {
6662 XMLName : report .XMLName ,
@@ -76,9 +72,12 @@ func convertTestReport(report TestReport) testreport.TestReport {
7672
7773func convertTestSuite (testSuite TestSuite ) testreport.TestSuite {
7874 convertedTestSuite := testreport.TestSuite {
79- XMLName : testSuite .XMLName ,
80- Name : testSuite .Name ,
81- Time : testSuite .Time ,
75+ XMLName : testSuite .XMLName ,
76+ Name : testSuite .Name ,
77+ Time : testSuite .Time ,
78+ Assertions : testSuite .Assertions ,
79+ Timestamp : testSuite .Timestamp ,
80+ File : testSuite .File ,
8281 }
8382
8483 tests := 0
@@ -94,6 +93,9 @@ func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
9493 if convertedTestCase .Failure != nil {
9594 failures ++
9695 }
96+ if convertedTestCase .Error != nil {
97+ errors ++
98+ }
9799 if convertedTestCase .Skipped != nil {
98100 skipped ++
99101 }
@@ -131,78 +133,74 @@ func flattenGroupedTestCases(testCases []TestCase) []TestCase {
131133 }
132134
133135 for _ , flakyFailure := range testCase .FlakyFailures {
134- flattenedTestCase .Failure = convertToFailure (flakyFailure .Type , flakyFailure .Message , flakyFailure .SystemErr )
136+ flattenedTestCase .Failure = & Failure {
137+ Type : flakyFailure .Type ,
138+ Message : flakyFailure .Message ,
139+ Value : flakyFailure .Value ,
140+ }
141+ flattenedTestCase .SystemErr = flakyFailure .SystemErr
142+ flattenedTestCase .SystemOut = flakyFailure .SystemOut
135143 flattenedTestCases = append (flattenedTestCases , flattenedTestCase )
136144 }
137145
146+ flattenedTestCase .Failure = nil
138147 for _ , flakyError := range testCase .FlakyErrors {
139- flattenedTestCase .Failure = convertToFailure (flakyError .Type , flakyError .Message , flakyError .SystemErr )
148+ flattenedTestCase .Error = & Error {
149+ Type : flakyError .Type ,
150+ Message : flakyError .Message ,
151+ Value : flakyError .Value ,
152+ }
153+ flattenedTestCase .SystemErr = flakyError .SystemErr
154+ flattenedTestCase .SystemOut = flakyError .SystemOut
140155 flattenedTestCases = append (flattenedTestCases , flattenedTestCase )
141156 }
142157
158+ flattenedTestCase .Error = nil
143159 for _ , rerunfailure := range testCase .RerunFailures {
144- flattenedTestCase .Failure = convertToFailure (rerunfailure .Type , rerunfailure .Message , rerunfailure .SystemErr )
160+ flattenedTestCase .Failure = & Failure {
161+ Type : rerunfailure .Type ,
162+ Message : rerunfailure .Message ,
163+ Value : rerunfailure .Value ,
164+ }
165+ flattenedTestCase .SystemErr = rerunfailure .SystemErr
166+ flattenedTestCase .SystemOut = rerunfailure .SystemOut
145167 flattenedTestCases = append (flattenedTestCases , flattenedTestCase )
146168 }
147169
170+ flattenedTestCase .Failure = nil
148171 for _ , rerunError := range testCase .RerunErrors {
149- flattenedTestCase .Failure = convertToFailure (rerunError .Type , rerunError .Message , rerunError .SystemErr )
172+ flattenedTestCase .Error = & Error {
173+ Type : rerunError .Type ,
174+ Message : rerunError .Message ,
175+ Value : rerunError .Value ,
176+ }
177+ flattenedTestCase .SystemErr = rerunError .SystemErr
178+ flattenedTestCase .SystemOut = rerunError .SystemOut
150179 flattenedTestCases = append (flattenedTestCases , flattenedTestCase )
151180 }
152181
153182 }
154183 return flattenedTestCases
155184}
156185
157- func convertToFailure (itemType , failureMessage , systemErr string ) * Failure {
158- var message string
159- if len (strings .TrimSpace (itemType )) > 0 {
160- message = itemType
161- }
162- if len (strings .TrimSpace (failureMessage )) > 0 {
163- if len (message ) > 0 {
164- message += ": "
165- }
166- message += failureMessage
167- }
168-
169- if len (strings .TrimSpace (systemErr )) > 0 {
170- if len (message ) > 0 {
171- message += "\n \n "
172- }
173- message += "System error:\n " + systemErr
174- }
175-
176- if len (message ) > 0 {
177- return & Failure {
178- Value : message ,
179- }
180- }
181- return nil
182- }
183-
184186func convertTestCase (testCase TestCase ) testreport.TestCase {
185187 convertedTestCase := testreport.TestCase {
186188 XMLName : testCase .XMLName ,
187189 ConfigurationHash : testCase .ConfigurationHash ,
188190 Name : testCase .Name ,
189191 ClassName : testCase .ClassName ,
190192 Time : testCase .Time ,
193+ Assertions : testCase .Assertions ,
194+ File : testCase .File ,
195+ Line : testCase .Line ,
191196 Failure : convertFailure (testCase .Failure ),
192197 Error : convertError (testCase .Error ),
193198 Skipped : convertSkipped (testCase .Skipped ),
199+ Properties : convertProperties (testCase .Properties ),
194200 SystemOut : convertSystemOut (testCase .SystemOut ),
195201 SystemErr : convertSystemErr (testCase .SystemErr ),
196- Properties : convertProperties (testCase .Properties ),
197202 }
198203
199- if convertedTestCase .Error != nil {
200- convertedTestCase .Failure = convertErrorToFailure (convertedTestCase .Error )
201- convertedTestCase .Error = nil
202- }
203-
204- enrichWithSystemOutputs (& convertedTestCase , testCase .SystemOut , testCase .SystemErr )
205-
206204 return convertedTestCase
207205}
208206
@@ -224,24 +222,24 @@ func convertProperties(properties *Properties) *testreport.Properties {
224222}
225223
226224func convertSystemOut (systemOut string ) * testreport.SystemOut {
227- if systemOut == "" {
225+ if len ( strings . TrimSpace ( systemOut )) == 0 {
228226 return nil
229227 }
230228
231229 return & testreport.SystemOut {
232230 XMLName : xml.Name {Local : "system-out" },
233- Value : systemOut ,
231+ Value : strings . TrimSpace ( systemOut ) ,
234232 }
235233}
236234
237235func convertSystemErr (systemErr string ) * testreport.SystemErr {
238- if systemErr == "" {
236+ if len ( strings . TrimSpace ( systemErr )) == 0 {
239237 return nil
240238 }
241239
242240 return & testreport.SystemErr {
243241 XMLName : xml.Name {Local : "system-err" },
244- Value : systemErr ,
242+ Value : strings . TrimSpace ( systemErr ) ,
245243 }
246244}
247245
@@ -250,15 +248,10 @@ func convertSkipped(skipped *Skipped) *testreport.Skipped {
250248 return nil
251249 }
252250
253- var parts []string
254-
255- if len (strings .TrimSpace (skipped .Message )) > 0 {
256- parts = append (parts , strings .TrimSpace (skipped .Message ))
257- }
258-
259251 return & testreport.Skipped {
260252 XMLName : xml.Name {Local : "skipped" },
261- Value : strings .Join (parts , "\n \n " ),
253+ Message : skipped .Message ,
254+ Value : strings .TrimSpace (skipped .Value ),
262255 }
263256}
264257
@@ -267,26 +260,11 @@ func convertFailure(failure *Failure) *testreport.Failure {
267260 return nil
268261 }
269262
270- var parts []string
271-
272- var attributes []string
273- if len (strings .TrimSpace (failure .Type )) > 0 {
274- attributes = append (attributes , failure .Type )
275- }
276- if len (strings .TrimSpace (failure .Message )) > 0 {
277- attributes = append (attributes , failure .Message )
278- }
279- if len (attributes ) > 0 {
280- parts = append (parts , strings .Join (attributes , ": " ))
281- }
282-
283- if len (strings .TrimSpace (failure .Value )) > 0 {
284- parts = append (parts , failure .Value )
285- }
286-
287263 return & testreport.Failure {
288264 XMLName : xml.Name {Local : "failure" },
289- Value : strings .Join (parts , "\n \n " ),
265+ Type : failure .Type ,
266+ Message : failure .Message ,
267+ Value : strings .TrimSpace (failure .Value ),
290268 }
291269}
292270
@@ -295,74 +273,10 @@ func convertError(error *Error) *testreport.Error {
295273 return nil
296274 }
297275
298- var parts []string
299-
300- var attributes []string
301- if len (strings .TrimSpace (error .Type )) > 0 {
302- attributes = append (attributes , error .Type )
303- }
304- if len (strings .TrimSpace (error .Message )) > 0 {
305- attributes = append (attributes , error .Message )
306- }
307- if len (attributes ) > 0 {
308- parts = append (parts , strings .Join (attributes , ": " ))
309- }
310-
311- if len (strings .TrimSpace (error .Value )) > 0 {
312- parts = append (parts , error .Value )
313- }
314-
315276 return & testreport.Error {
316277 XMLName : xml.Name {Local : "error" },
317- Value : strings .Join (parts , "\n \n " ),
318- }
319- }
320-
321- func convertErrorToFailure (error * testreport.Error ) * testreport.Failure {
322- if error == nil {
323- return nil
324- }
325-
326- return & testreport.Failure {
327- XMLName : xml.Name {Local : "failure" },
328- Value : error .Value ,
329- }
330- }
331-
332- func enrichWithSystemOutputs (testCase * testreport.TestCase , systemOut , systemErr string ) {
333- testOutputs := []string {}
334-
335- if len (strings .TrimSpace (systemErr )) > 0 {
336- testOutputs = append (testOutputs , "System error:\n " + systemErr )
337- }
338-
339- if len (strings .TrimSpace (systemOut )) > 0 {
340- testOutputs = append (testOutputs , "System output:\n " + systemOut )
341- }
342-
343- if (len (testOutputs )) == 0 {
344- return
345- }
346-
347- combinedOutput := strings .Join (testOutputs , "\n \n " )
348-
349- if testCase .Error != nil {
350- if len (strings .TrimSpace (testCase .Error .Value )) > 0 {
351- testCase .Error .Value = testCase .Error .Value + "\n \n " + combinedOutput
352- } else {
353- testCase .Error .Value = combinedOutput
354- }
355- } else if testCase .Failure != nil {
356- if len (strings .TrimSpace (testCase .Failure .Value )) > 0 {
357- testCase .Failure .Value = testCase .Failure .Value + "\n \n " + combinedOutput
358- } else {
359- testCase .Failure .Value = combinedOutput
360- }
361- } else if testCase .Skipped != nil {
362- if len (strings .TrimSpace (testCase .Skipped .Value )) > 0 {
363- testCase .Skipped .Value = testCase .Skipped .Value + "\n \n " + combinedOutput
364- } else {
365- testCase .Skipped .Value = combinedOutput
366- }
278+ Type : error .Type ,
279+ Message : error .Message ,
280+ Value : strings .TrimSpace (error .Value ),
367281 }
368282}
0 commit comments