Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testsuite name in the generated junit-runner.xml file #93

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result
if err != nil {
return errors.Wrap(err, "could not create runner output")
}
writer := metadata.NewWriter(junitRunner)
writer := metadata.NewWriter("kubetest2", junitRunner)
// defer writing out the metadata on exit
// NOTE: defer is LIFO, so this should actually be the finish time
defer func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/metadata/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func NewJUnitError(inner error, systemOut string) error {
// A build (column in testgrid) is composed of one or more TestSuites.
type testSuite struct {
XMLName xml.Name `xml:"testsuite"`
Name string `xml:"name,attr"`
Failures int `xml:"failures,attr"`
Tests int `xml:"tests,attr"`
Time float64 `xml:"time,attr"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/metadata/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type Writer struct {
// NewWriter constructs a new writer, the junit_runner.xml contents
// will be written to runnerOut, with the top level kubetest2 stages as
// metadata (Up, Down, etc.)
func NewWriter(runnerOut io.Writer) *Writer {
suite := testSuite{}
func NewWriter(suiteName string, runnerOut io.Writer) *Writer {
suite := testSuite{Name: suiteName}
return &Writer{
suite: suite,
runnerOut: runnerOut,
Expand Down
10 changes: 5 additions & 5 deletions pkg/metadata/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestWriter(t *testing.T) {
},
expectedOutput: strings.TrimPrefix(
`
<?xml version="1.0" encoding="UTF-8"?><testsuite failures="0" tests="1" time="3">
<?xml version="1.0" encoding="UTF-8"?><testsuite name="kubetest2" failures="0" tests="1" time="3">
<testcase name="noop" time="1"></testcase>
</testsuite>`,
"\n",
Expand All @@ -89,7 +89,7 @@ func TestWriter(t *testing.T) {
},
expectedOutput: strings.TrimPrefix(
`
<?xml version="1.0" encoding="UTF-8"?><testsuite failures="1" tests="1" time="3">
<?xml version="1.0" encoding="UTF-8"?><testsuite name="kubetest2" failures="1" tests="1" time="3">
<testcase name="always fails" time="1">
<failure>oh noes</failure>
</testcase>
Expand All @@ -113,7 +113,7 @@ func TestWriter(t *testing.T) {
},
expectedOutput: strings.TrimPrefix(
`
<?xml version="1.0" encoding="UTF-8"?><testsuite failures="1" tests="1" time="3">
<?xml version="1.0" encoding="UTF-8"?><testsuite name="kubetest2" failures="1" tests="1" time="3">
<testcase name="always fails (junitError)" time="1">
<failure>on noes</failure>
<system-out>uh oh</system-out>
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestWriter(t *testing.T) {
},
expectedOutput: strings.TrimPrefix(
`
<?xml version="1.0" encoding="UTF-8"?><testsuite failures="1" tests="3" time="7">
<?xml version="1.0" encoding="UTF-8"?><testsuite name="kubetest2" failures="1" tests="3" time="7">
<testcase name="noop" time="1"></testcase>
<testcase name="noop2" time="1"></testcase>
<testcase name="always fails (junitError)" time="1">
Expand All @@ -166,7 +166,7 @@ func TestWriter(t *testing.T) {
// fake output io.WriteCloser
runnerOut := bytes.NewBuffer([]byte{})
// create a new writer and fake out the time
w := NewWriter(runnerOut)
w := NewWriter("kubetest2", runnerOut)
w.timeNow = makeFakeNow()
w.start = w.timeNow()
// run all the steps
Expand Down