forked from goddenrich/go-junit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingest_test.go
81 lines (75 loc) · 1.77 KB
/
ingest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright Josh Komoroske. All rights reserved.
// Use of this source code is governed by the MIT license,
// a copy of which can be found in the LICENSE.txt file.
package junit
import (
"bytes"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestInjest(t *testing.T) {
tests := []struct {
title string
input []byte
expected []Suite
}{
{
title: "xml input",
input: []byte(`<testsuites><testsuite errors="0" failures="1" file="Foo.java"><testcase name="unit tests" file="Foo.java"/></testsuite></testsuites>`),
expected: []Suite{
{
Tests: []Test{
{
Name: "unit tests",
Status: "passed",
Properties: map[string]string{
"file": "Foo.java",
"name": "unit tests",
},
},
},
Totals: Totals{
Tests: 1,
Passed: 1,
},
},
},
},
{
title: "xml input with skipped test",
input: []byte(`<testsuites><testsuite errors="0" skipped="1" file="Foo.java"><testcase name="unit tests" file="Foo.java"><skipped message="foo skip message"/></testcase></testsuite></testsuites>`),
expected: []Suite{
{
Tests: []Test{
{
Name: "unit tests",
Status: "skipped",
Properties: map[string]string{
"file": "Foo.java",
"name": "unit tests",
},
Error: Error{
Message: "foo skip message",
},
},
},
Totals: Totals{
Tests: 1,
Passed: 0,
Skipped: 1,
},
},
},
},
}
for index, test := range tests {
name := fmt.Sprintf("#%d - %s", index+1, test.title)
t.Run(name, func(t *testing.T) {
actual, err := Ingest(bytes.NewReader(test.input))
require.Nil(t, err)
require.NotEmpty(t, actual)
require.Equal(t, test.expected, actual)
})
}
}