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

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