-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatter_test.go
64 lines (58 loc) · 1.3 KB
/
formatter_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
package main
import (
"bytes"
"encoding/xml"
"testing"
)
func TestSuites_Unmarshal(t *testing.T) {
tests := []struct {
desc string
suites JUnitTestSuites
noXMLHeader bool
goVersion string
}{
{
desc: "Suites should marshal back and forth",
suites: JUnitTestSuites{
Suites: []JUnitTestSuite{
{
Name: "suite1",
TestCases: []JUnitTestCase{
{Name: "test1-1"},
{Name: "test1-2"},
},
},
{
Name: "suite2",
TestCases: []JUnitTestCase{
{Name: "test2-1"},
{Name: "test2-2"},
},
},
},
},
},
}
for _, test := range tests {
t.Logf("Test case: %v", test.desc)
initialBytes, err := xml.Marshal(test.suites)
if err != nil {
t.Fatalf("Expected no failure when generating xml; got %v", err)
}
var suites JUnitTestSuites
err = xml.Unmarshal(initialBytes, &suites)
if err != nil {
t.Fatalf("Expected no failure when unmarshaling; got %v", err)
}
newBytes, err := xml.Marshal(suites)
if err != nil {
t.Fatalf("Expected no failure when generating xml again; got %v", err)
}
if !bytes.Equal(newBytes, initialBytes) {
t.Errorf("Expected the same result when marshal/unmarshal/marshal. Expected\n%v\n\t but got\n%v",
string(initialBytes),
string(newBytes),
)
}
}
}