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

Commit 6465646

Browse files
authored
Merge pull request #1196 from freehan/junitfix
fix junit xml with testsuites tag
2 parents 8b3c3bf + ebfd0e7 commit 6465646

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.
@@ -254,21 +255,37 @@ func getJUnitFailures(r io.Reader) (failures map[string]string, err error) {
254255
FailCount int `xml:"failures,attr"`
255256
Testcases []Testcase `xml:"testcase"`
256257
}
257-
ts := &Testsuite{}
258-
// TODO: this full parse is a bit slower than the old scanf routine--
259-
// could switch back for the case where we only care whether there was
260-
// a failure or not if that is an issue in practice.
261-
err = xml.NewDecoder(r).Decode(ts)
258+
type Testsuites struct {
259+
TestSuites []Testsuite `xml:"testsuite"`
260+
}
261+
var testSuiteList []Testsuite
262+
failures = map[string]string{}
263+
testSuites := &Testsuites{}
264+
testSuite := &Testsuite{}
265+
b, err := ioutil.ReadAll(r)
262266
if err != nil {
263267
return failures, err
264268
}
265-
if ts.FailCount == 0 {
266-
return nil, nil
269+
// first try to parse the result with <testsuites> as top tag
270+
err = xml.Unmarshal(b, testSuites)
271+
if err == nil && len(testSuites.TestSuites) > 0 {
272+
testSuiteList = testSuites.TestSuites
273+
} else {
274+
// second try to parse the result with <testsuite> as top tag
275+
err = xml.Unmarshal(b, testSuite)
276+
if err != nil {
277+
return nil, err
278+
}
279+
testSuiteList = []Testsuite{*testSuite}
267280
}
268-
failures = map[string]string{}
269-
for _, tc := range ts.Testcases {
270-
if tc.Failure != "" {
271-
failures[fmt.Sprintf("%v {%v}", tc.Name, tc.ClassName)] = tc.Failure
281+
for _, ts := range testSuiteList {
282+
if ts.FailCount == 0 {
283+
continue
284+
}
285+
for _, tc := range ts.Testcases {
286+
if tc.Failure != "" {
287+
failures[fmt.Sprintf("%v {%v}", tc.Name, tc.ClassName)] = tc.Failure
288+
}
272289
}
273290
}
274291
return failures, nil

mungegithub/mungers/e2e/e2e_test.go

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

391+
func getRealJUnitFailureWithTestSuitesTag() []byte {
392+
return []byte(`<?xml version="1.0" encoding="UTF-8"?>
393+
<testsuites>
394+
<testsuite tests="52" failures="2" time="374.434" name="k8s.io/kubernetes/test/integration">
395+
<properties>
396+
<property name="go.version" value="go1.6.2"></property>
397+
</properties>
398+
<testcase classname="integration" name="TestMasterProcessMetrics" time="0.070"></testcase>
399+
<testcase classname="integration" name="TestApiserverMetrics" time="0.070"></testcase>
400+
<testcase classname="integration" name="TestMasterExportsSymbols" time="0.000"></testcase>
401+
<testcase classname="integration" name="TestPersistentVolumeRecycler" time="20.460"></testcase>
402+
<testcase classname="integration" name="TestPersistentVolumeMultiPVs" time="10.240">
403+
<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>
404+
</testcase>
405+
<testcase classname="integration" name="TestPersistentVolumeMultiPVsPVCs" time="3.370">
406+
<failure message="Failed" type="">persistent_volumes_test.go:379: PVC &#34;pvc-0&#34; is not bound</failure>
407+
</testcase>
408+
<testcase classname="integration" name="TestPersistentVolumeMultiPVsDiffAccessModes" time="10.110"></testcase>
409+
</testsuite>
410+
</testsuites>
411+
`)
412+
}
413+
391414
func TestCheckGCSWeakBuilds(t *testing.T) {
392415
latestBuildNumberFoo := 42
393416
latestBuildNumberBar := 44
@@ -585,6 +608,7 @@ func TestCheckGCSWeakBuilds(t *testing.T) {
585608
}
586609

587610
func TestJUnitFailureParse(t *testing.T) {
611+
//parse junit xml result with <testsuite> as top tag
588612
junitFailReader := bytes.NewReader(getRealJUnitFailure())
589613
got, err := getJUnitFailures(junitFailReader)
590614
if err != nil {
@@ -597,4 +621,17 @@ func TestJUnitFailureParse(t *testing.T) {
597621
}, got; !reflect.DeepEqual(e, a) {
598622
t.Errorf("Expected %v, got %v", e, a)
599623
}
624+
625+
//parse junit xml result with <testsuites> as top tag
626+
junitFailReader = bytes.NewReader(getRealJUnitFailureWithTestSuitesTag())
627+
got, err = getJUnitFailures(junitFailReader)
628+
if err != nil {
629+
t.Fatalf("Parse error? %v", err)
630+
}
631+
if e, a := map[string]string{
632+
"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",
633+
"TestPersistentVolumeMultiPVsPVCs {integration}": "persistent_volumes_test.go:379: PVC &#34;pvc-0&#34; is not bound",
634+
}, got; reflect.DeepEqual(e, a) {
635+
t.Errorf("Expected %v, got %v", e, a)
636+
}
600637
}

0 commit comments

Comments
 (0)