Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit ebfd0e7

Browse files
committed
fix junit xml with testsuites tag
1 parent cefb6c1 commit ebfd0e7

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed

mungegithub/mungers/e2e/e2e.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/kubernetes/pkg/util/sets"
3131

3232
"github.com/golang/glog"
33+
"io/ioutil"
3334
)
3435

3536
// E2ETester can be queried for E2E job stability.
@@ -231,21 +232,37 @@ func getJUnitFailures(r io.Reader) (failures map[string]string, err error) {
231232
FailCount int `xml:"failures,attr"`
232233
Testcases []Testcase `xml:"testcase"`
233234
}
234-
ts := &Testsuite{}
235-
// TODO: this full parse is a bit slower than the old scanf routine--
236-
// could switch back for the case where we only care whether there was
237-
// a failure or not if that is an issue in practice.
238-
err = xml.NewDecoder(r).Decode(ts)
235+
type Testsuites struct {
236+
TestSuites []Testsuite `xml:"testsuite"`
237+
}
238+
var testSuiteList []Testsuite
239+
failures = map[string]string{}
240+
testSuites := &Testsuites{}
241+
testSuite := &Testsuite{}
242+
b, err := ioutil.ReadAll(r)
239243
if err != nil {
240244
return failures, err
241245
}
242-
if ts.FailCount == 0 {
243-
return nil, nil
246+
// first try to parse the result with <testsuites> as top tag
247+
err = xml.Unmarshal(b, testSuites)
248+
if err == nil && len(testSuites.TestSuites) > 0 {
249+
testSuiteList = testSuites.TestSuites
250+
} else {
251+
// second try to parse the result with <testsuite> as top tag
252+
err = xml.Unmarshal(b, testSuite)
253+
if err != nil {
254+
return nil, err
255+
}
256+
testSuiteList = []Testsuite{*testSuite}
244257
}
245-
failures = map[string]string{}
246-
for _, tc := range ts.Testcases {
247-
if tc.Failure != "" {
248-
failures[fmt.Sprintf("%v {%v}", tc.Name, tc.ClassName)] = tc.Failure
258+
for _, ts := range testSuiteList {
259+
if ts.FailCount == 0 {
260+
continue
261+
}
262+
for _, tc := range ts.Testcases {
263+
if tc.Failure != "" {
264+
failures[fmt.Sprintf("%v {%v}", tc.Name, tc.ClassName)] = tc.Failure
265+
}
249266
}
250267
}
251268
return failures, nil

mungegithub/mungers/e2e/e2e_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,29 @@ func getRealJUnitFailure() []byte {
366366
</testsuite>`)
367367
}
368368

369+
func getRealJUnitFailureWithTestSuitesTag() []byte {
370+
return []byte(`<?xml version="1.0" encoding="UTF-8"?>
371+
<testsuites>
372+
<testsuite tests="52" failures="2" time="374.434" name="k8s.io/kubernetes/test/integration">
373+
<properties>
374+
<property name="go.version" value="go1.6.2"></property>
375+
</properties>
376+
<testcase classname="integration" name="TestMasterProcessMetrics" time="0.070"></testcase>
377+
<testcase classname="integration" name="TestApiserverMetrics" time="0.070"></testcase>
378+
<testcase classname="integration" name="TestMasterExportsSymbols" time="0.000"></testcase>
379+
<testcase classname="integration" name="TestPersistentVolumeRecycler" time="20.460"></testcase>
380+
<testcase classname="integration" name="TestPersistentVolumeMultiPVs" time="10.240">
381+
<failure message="Failed" type="">persistent_volumes_test.go:254: volumes created&#xA;persistent_volumes_test.go:260: claim created&#xA;persistent_volumes_test.go:264: volume bound&#xA;persistent_volumes_test.go:266: claim bound&#xA;persistent_volumes_test.go:284: Bind mismatch! Expected pvc-2 capacity 50000000000 but got fake-pvc-72 capacity 5000000000</failure>
382+
</testcase>
383+
<testcase classname="integration" name="TestPersistentVolumeMultiPVsPVCs" time="3.370">
384+
<failure message="Failed" type="">persistent_volumes_test.go:379: PVC &#34;pvc-0&#34; is not bound</failure>
385+
</testcase>
386+
<testcase classname="integration" name="TestPersistentVolumeMultiPVsDiffAccessModes" time="10.110"></testcase>
387+
</testsuite>
388+
</testsuites>
389+
`)
390+
}
391+
369392
func TestCheckGCSWeakBuilds(t *testing.T) {
370393
latestBuildNumberFoo := 42
371394
latestBuildNumberBar := 44
@@ -563,6 +586,7 @@ func TestCheckGCSWeakBuilds(t *testing.T) {
563586
}
564587

565588
func TestJUnitFailureParse(t *testing.T) {
589+
//parse junit xml result with <testsuite> as top tag
566590
junitFailReader := bytes.NewReader(getRealJUnitFailure())
567591
got, err := getJUnitFailures(junitFailReader)
568592
if err != nil {
@@ -575,4 +599,17 @@ func TestJUnitFailureParse(t *testing.T) {
575599
}, got; !reflect.DeepEqual(e, a) {
576600
t.Errorf("Expected %v, got %v", e, a)
577601
}
602+
603+
//parse junit xml result with <testsuites> as top tag
604+
junitFailReader = bytes.NewReader(getRealJUnitFailureWithTestSuitesTag())
605+
got, err = getJUnitFailures(junitFailReader)
606+
if err != nil {
607+
t.Fatalf("Parse error? %v", err)
608+
}
609+
if e, a := map[string]string{
610+
"TestPersistentVolumeMultiPVs {integration}": "persistent_volumes_test.go:254: volumes created&#xA;persistent_volumes_test.go:260: claim created&#xA;persistent_volumes_test.go:264: volume bound&#xA;persistent_volumes_test.go:266: claim bound&#xA;persistent_volumes_test.go:284: Bind mismatch! Expected pvc-2 capacity 50000000000 but got fake-pvc-72 capacity 5000000000",
611+
"TestPersistentVolumeMultiPVsPVCs {integration}": "persistent_volumes_test.go:379: PVC &#34;pvc-0&#34; is not bound",
612+
}, got; reflect.DeepEqual(e, a) {
613+
t.Errorf("Expected %v, got %v", e, a)
614+
}
578615
}

0 commit comments

Comments
 (0)