From 6d2ab46d4f2ec7f19cdbf496470d30832a10f53d Mon Sep 17 00:00:00 2001 From: Nick Palmer Date: Tue, 13 Jan 2015 18:35:34 -0800 Subject: [PATCH] Add surrounding tag. * If a test log contains more than one package we need to wrap it in a element in order to be valid xml. Bamboo cannot read the file if it is not valid xml. --- go-junit-report_test.go | 2 +- junit-formatter.go | 10 ++++++++-- tests/01-report.xml | 16 +++++++++------- tests/02-report.xml | 20 +++++++++++--------- tests/03-report.xml | 20 +++++++++++--------- tests/04-report.xml | 16 +++++++++------- tests/05-report.xml | 16 +++++++++------- 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/go-junit-report_test.go b/go-junit-report_test.go index c268f0a..1d5e349 100644 --- a/go-junit-report_test.go +++ b/go-junit-report_test.go @@ -233,7 +233,7 @@ func TestJUnitFormatter(t *testing.T) { } if string(junitReport.Bytes()) != report { - t.Fatalf("Report xml ==\n%s, want\n%s", string(junitReport.Bytes()), report) + t.Fatalf("Fail: %s Report xml ==\n%s, want\n%s", testCase.name, string(junitReport.Bytes()), report) } } } diff --git a/junit-formatter.go b/junit-formatter.go index 2f1f887..03cff30 100644 --- a/junit-formatter.go +++ b/junit-formatter.go @@ -9,6 +9,11 @@ import ( "strings" ) +type JUnitTestSuites struct { + XMLName xml.Name `xml:"testsuites"` + Suites []JUnitTestSuite +} + type JUnitTestSuite struct { XMLName xml.Name `xml:"testsuite"` Tests int `xml:"tests,attr"` @@ -53,7 +58,7 @@ func NewJUnitProperty(name, value string) JUnitProperty { // JUnitReportXML writes a junit xml representation of the given report to w // in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error { - suites := []JUnitTestSuite{} + suites := JUnitTestSuites{} // convert Report to JUnit test suites for _, pkg := range report.Packages { @@ -100,7 +105,7 @@ func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error { ts.TestCases = append(ts.TestCases, testCase) } - suites = append(suites, ts) + suites.Suites = append(suites.Suites, ts) } // to xml @@ -114,6 +119,7 @@ func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error { if !noXmlHeader { writer.WriteString(xml.Header) } + writer.Write(bytes) writer.WriteByte('\n') writer.Flush() diff --git a/tests/01-report.xml b/tests/01-report.xml index 2585b80..f8f1038 100644 --- a/tests/01-report.xml +++ b/tests/01-report.xml @@ -1,8 +1,10 @@ - - - - - - - + + + + + + + + + diff --git a/tests/02-report.xml b/tests/02-report.xml index bfa33d7..23a4f0f 100644 --- a/tests/02-report.xml +++ b/tests/02-report.xml @@ -1,10 +1,12 @@ - - - - - - file_test.go:11: Error message file_test.go:11: Longer error message. - - - + + + + + + + file_test.go:11: Error message file_test.go:11: Longer error message. + + + + diff --git a/tests/03-report.xml b/tests/03-report.xml index 71f287d..e67e5ef 100644 --- a/tests/03-report.xml +++ b/tests/03-report.xml @@ -1,10 +1,12 @@ - - - - - - - - - + + + + + + + + + + + diff --git a/tests/04-report.xml b/tests/04-report.xml index 2585b80..f8f1038 100644 --- a/tests/04-report.xml +++ b/tests/04-report.xml @@ -1,8 +1,10 @@ - - - - - - - + + + + + + + + + diff --git a/tests/05-report.xml b/tests/05-report.xml index 5a372aa..125307a 100644 --- a/tests/05-report.xml +++ b/tests/05-report.xml @@ -1,7 +1,9 @@ - - - - - - - + + + + + + + + +