Skip to content

Commit 696df52

Browse files
authored
Support recursive testsuites in CVS export. (#29)
1 parent 412d2e2 commit 696df52

2 files changed

Lines changed: 81 additions & 17 deletions

File tree

main.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,8 @@ func junit2csv(testSuites []junit.Suite, p params, output io.Writer) error {
436436
return fmt.Errorf("coud not write header: %w", err)
437437
}
438438
for _, ts := range testSuites {
439-
for _, tc := range ts.Tests {
440-
duration := fmt.Sprintf("%d", tc.Duration.Milliseconds())
441-
row := []string{
442-
p.BuildId, // BuildId
443-
p.timestamp, // Timestamp
444-
tc.Classname, // Classname
445-
tc.Name, // Name
446-
duration, // Duration
447-
string(tc.Status), // Status
448-
p.JobName, // JobName
449-
p.BuildTag, // BuildTag
450-
}
451-
err := w.Write(row)
452-
if err != nil {
453-
return fmt.Errorf("coud not write row: %w", err)
454-
}
439+
if err = testSuiteToCSV(ts, p, w); err != nil {
440+
return err
455441
}
456442
}
457443
w.Flush()
@@ -461,6 +447,32 @@ func junit2csv(testSuites []junit.Suite, p params, output io.Writer) error {
461447
return nil
462448
}
463449

450+
func testSuiteToCSV(ts junit.Suite, p params, w *csv.Writer) error {
451+
for _, subTs := range ts.Suites {
452+
if err := testSuiteToCSV(subTs, p, w); err != nil {
453+
return err
454+
}
455+
}
456+
for _, tc := range ts.Tests {
457+
duration := fmt.Sprintf("%d", tc.Duration.Milliseconds())
458+
row := []string{
459+
p.BuildId, // BuildId
460+
p.timestamp, // Timestamp
461+
tc.Classname, // Classname
462+
tc.Name, // Name
463+
duration, // Duration
464+
string(tc.Status), // Status
465+
p.JobName, // JobName
466+
p.BuildTag, // BuildTag
467+
}
468+
err := w.Write(row)
469+
if err != nil {
470+
return fmt.Errorf("coud not write row: %w", err)
471+
}
472+
}
473+
return nil
474+
}
475+
464476
func (j junit2jira) findFailedTests(testSuites []junit.Suite) ([]testCase, error) {
465477
failedTests := make([]testCase, 0)
466478
for _, ts := range testSuites {

main_test.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ func TestCsvOutput(t *testing.T) {
313313
timestamp: "time",
314314
}
315315
buf := bytes.NewBufferString("")
316-
testSuites, err := junit.IngestDir("testdata/jira/TEST-DefaultPoliciesTest.xml")
316+
testSuites, err := junit.IngestFiles([]string{
317+
"testdata/jira/TEST-DefaultPoliciesTest.xml",
318+
"testdata/jira/kuttl-report.xml",
319+
})
317320
assert.NoError(t, err)
318321
err = junit2csv(testSuites, p, buf)
319322
assert.NoError(t, err)
@@ -334,6 +337,55 @@ func TestCsvOutput(t *testing.T) {
334337
1,time,DefaultPoliciesTest,Verify that built-in services don't trigger unexpected alerts,0,skipped,"comma ,",0.0.0
335338
1,time,DefaultPoliciesTest,Verify that alert counts API is consistent with alerts,0,skipped,"comma ,",0.0.0
336339
1,time,DefaultPoliciesTest,Verify that alert groups API is consistent with alerts,0,skipped,"comma ,",0.0.0
340+
1,time,central-basic,setup,0,passed,"comma ,",0.0.0
341+
1,time,central-basic,step 0-image-pull-secrets,0,passed,"comma ,",0.0.0
342+
1,time,central-basic,step 10-central-cr,0,passed,"comma ,",0.0.0
343+
1,time,central-basic,step 11-,0,passed,"comma ,",0.0.0
344+
1,time,central-basic,step 20-verify-password,0,passed,"comma ,",0.0.0
345+
1,time,central-basic,step 30-change-password,0,passed,"comma ,",0.0.0
346+
1,time,central-basic,step 40-reconcile,0,passed,"comma ,",0.0.0
347+
1,time,central-basic,step 60-use-new-password,0,passed,"comma ,",0.0.0
348+
1,time,central-basic,step 75-switch-to-external-central-db,0,passed,"comma ,",0.0.0
349+
1,time,central-basic,step 76-switch-back-to-internal-central-db,0,passed,"comma ,",0.0.0
350+
1,time,central-basic,step 90-activate-scanner-v4,0,failed,"comma ,",0.0.0
351+
1,time,central-misc,setup,0,passed,"comma ,",0.0.0
352+
1,time,central-misc,step 0-image-pull-secrets,0,passed,"comma ,",0.0.0
353+
1,time,central-misc,step 10-central-cr,0,passed,"comma ,",0.0.0
354+
1,time,central-misc,step 11-,0,passed,"comma ,",0.0.0
355+
1,time,central-misc,step 40-enable-declarative-config,0,passed,"comma ,",0.0.0
356+
1,time,central-misc,step 41-disable-declarative-config,0,passed,"comma ,",0.0.0
357+
1,time,central-misc,step 61-set-expose-monitoring,0,passed,"comma ,",0.0.0
358+
1,time,central-misc,step 62-,0,passed,"comma ,",0.0.0
359+
1,time,central-misc,step 63-unset-expose-monitoring,0,passed,"comma ,",0.0.0
360+
1,time,central-misc,step 64-,0,passed,"comma ,",0.0.0
361+
1,time,central-misc,step 80-enable-telemetry,0,passed,"comma ,",0.0.0
362+
1,time,central-misc,step 81-disable-telemetry,0,passed,"comma ,",0.0.0
363+
1,time,central-misc,step 85-add-additional-ca,0,passed,"comma ,",0.0.0
364+
1,time,central-misc,step 900-delete-cr,0,passed,"comma ,",0.0.0
365+
1,time,central-misc,step 990-,0,passed,"comma ,",0.0.0
366+
1,time,metrics,setup,0,passed,"comma ,",0.0.0
367+
1,time,metrics,step 100-rbac,0,passed,"comma ,",0.0.0
368+
1,time,metrics,step 200-access-no-auth,0,passed,"comma ,",0.0.0
369+
1,time,sc-basic,setup,0,passed,"comma ,",0.0.0
370+
1,time,sc-basic,step 0-image-pull-secrets,0,passed,"comma ,",0.0.0
371+
1,time,sc-basic,step 5-central-cr,0,passed,"comma ,",0.0.0
372+
1,time,sc-basic,step 7-fetch-bundle,0,passed,"comma ,",0.0.0
373+
1,time,sc-basic,step 10-secured-cluster-cr,0,passed,"comma ,",0.0.0
374+
1,time,sc-basic,step 12-,0,passed,"comma ,",0.0.0
375+
1,time,sc-basic,step 13-,0,passed,"comma ,",0.0.0
376+
1,time,sc-basic,step 14-,0,passed,"comma ,",0.0.0
377+
1,time,sc-basic,step 15-,0,passed,"comma ,",0.0.0
378+
1,time,sc-basic,step 16-,0,passed,"comma ,",0.0.0
379+
1,time,sc-basic,step 20-try-change-cluster-name,0,passed,"comma ,",0.0.0
380+
1,time,sc-basic,step 30-change-cluster-name-back,0,passed,"comma ,",0.0.0
381+
1,time,sc-basic,step 40-enable-monitoring,0,passed,"comma ,",0.0.0
382+
1,time,sc-basic,step 41-,0,passed,"comma ,",0.0.0
383+
1,time,sc-basic,step 42-disable-monitoring,0,passed,"comma ,",0.0.0
384+
1,time,sc-basic,step 43-,0,passed,"comma ,",0.0.0
385+
1,time,sc-basic,step 900-delete-central-cr,0,passed,"comma ,",0.0.0
386+
1,time,sc-basic,step 910-,0,passed,"comma ,",0.0.0
387+
1,time,sc-basic,step 950-delete-secured-cluster-cr,0,passed,"comma ,",0.0.0
388+
1,time,sc-basic,step 990-,0,passed,"comma ,",0.0.0
337389
`
338390
assert.Equal(t, expected, buf.String())
339391

0 commit comments

Comments
 (0)