-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarshalling_test.go
More file actions
70 lines (63 loc) · 1.37 KB
/
marshalling_test.go
File metadata and controls
70 lines (63 loc) · 1.37 KB
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
package restapi
import (
"encoding/xml"
"testing"
"github.com/blugnu/test"
)
func TestMarshalling(t *testing.T) {
// ARRANGE
testcases := []struct {
scenario string
exec func(t *testing.T)
}{
{scenario: "application/json",
exec: func(t *testing.T) {
// ACT
result, _ := marshal["application/json"](struct{ A int }{A: 1})
// ASSERT
test.That(t, string(result)).Equals(`{"A":1}`)
},
},
{scenario: "application/xml",
exec: func(t *testing.T) {
// ACT
result, _ := marshal["application/xml"](struct {
XMLName xml.Name
A int
}{
XMLName: xml.Name{Local: "struct"},
A: 1,
})
// ASSERT
test.That(t, string(result)).Equals(`<struct><A>1</A></struct>`)
},
},
{scenario: "text/json",
exec: func(t *testing.T) {
// ACT
result, _ := marshal["text/json"](struct{ A int }{A: 1})
// ASSERT
test.That(t, string(result)).Equals("{\n \"A\": 1\n}")
},
},
{scenario: "text/xml",
exec: func(t *testing.T) {
// ACT
result, _ := marshal["text/xml"](struct {
XMLName xml.Name
A int
}{
XMLName: xml.Name{Local: "struct"},
A: 1,
})
// ASSERT
test.That(t, string(result)).Equals("<struct>\n <A>1</A>\n</struct>")
},
},
}
for _, tc := range testcases {
t.Run(tc.scenario, func(t *testing.T) {
tc.exec(t)
})
}
}