Add surrounding <testsuites> tag.

* If a test log contains more than one package we need to wrap it
  in a <testsuites> element in order to be valid xml. Bamboo
  cannot read the file if it is not valid xml.
This commit is contained in:
Nick Palmer 2015-01-13 18:35:34 -08:00
parent 18ee6df2f2
commit 6d2ab46d4f
7 changed files with 58 additions and 42 deletions

View File

@ -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)
}
}
}

View File

@ -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()

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="2" failures="0" time="0.160" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.060"></testcase>
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
</testsuite>
<testsuites>
<testsuite tests="2" failures="0" time="0.160" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.060"></testcase>
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
</testsuite>
</testsuites>

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="2" failures="1" time="0.151" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.020">
<failure message="Failed" type="">file_test.go:11: Error message&#xA;file_test.go:11: Longer&#xA;&#x9;error&#xA;&#x9;message.</failure>
</testcase>
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
</testsuite>
<testsuites>
<testsuite tests="2" failures="1" time="0.151" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.020">
<failure message="Failed" type="">file_test.go:11: Error message&#xA;file_test.go:11: Longer&#xA;&#x9;error&#xA;&#x9;message.</failure>
</testcase>
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
</testsuite>
</testsuites>

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="2" failures="0" time="0.150" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.020">
<skipped message="file_test.go:11: Skip message"></skipped>
</testcase>
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
</testsuite>
<testsuites>
<testsuite tests="2" failures="0" time="0.150" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.020">
<skipped message="file_test.go:11: Skip message"></skipped>
</testcase>
<testcase classname="name" name="TestTwo" time="0.130"></testcase>
</testsuite>
</testsuites>

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="2" failures="0" time="0.160" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.060"></testcase>
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
</testsuite>
<testsuites>
<testsuite tests="2" failures="0" time="0.160" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.060"></testcase>
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
</testsuite>
</testsuites>

View File

@ -1,7 +1,9 @@
<testsuite tests="2" failures="0" time="0.160" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.060"></testcase>
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
</testsuite>
<testsuites>
<testsuite tests="2" failures="0" time="0.160" name="package/name">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="name" name="TestOne" time="0.060"></testcase>
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
</testsuite>
</testsuites>