-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_core_test.go
66 lines (52 loc) · 1.39 KB
/
client_core_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
package mingo
import (
"testing"
)
func TestGetRequestBody(t *testing.T) {
// initialization
client := client{}
// execution
t.Run("nobodynilresponse", func(t *testing.T) {
body, err := client.getReqBody(nil, "")
// validation
if err != nil {
t.Error("no error expected here (nil body)")
}
if body != nil {
t.Error("no body expected here (nil body)")
}
})
t.Run("bodywithjson", func(t *testing.T) {
reqBody := []string{"one", "two"}
body, err := client.getReqBody(reqBody, "application/json")
// validation
if err != nil {
t.Error("no error expected marshaling (json body)")
}
if string(body) != `["one","two"]` {
t.Error("no body expected here (marhsal body)")
}
})
t.Run("bodywithxml", func(t *testing.T) {
reqBody := []string{"one", "two"}
body, err := client.getReqBody(reqBody, "application/xml")
// validation
if err != nil {
t.Error("no error expected marshaling (xml body)")
}
if string(body) != `<string>one</string><string>two</string>` {
t.Error("no body expected here (xml body)")
}
})
t.Run("defaultbodythatisjson", func(t *testing.T) {
reqBody := []string{"one", "two"}
body, err := client.getReqBody(reqBody, "")
// validation
if err != nil {
t.Error("no error expected here (default json body)")
}
if string(body) != `["one","two"]` {
t.Error("no body expected marshaling (default json body)")
}
})
}