forked from Eun/go-hit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_send_body_test.go
110 lines (97 loc) · 2.75 KB
/
clear_send_body_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package hit_test
import (
"testing"
. "github.com/Eun/go-hit"
)
func TestClearSendBody_JSON(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("all", func(t *testing.T) {
ExpectError(t,
Do(
Post(s.URL),
Send().Body().JSON("Hello World"),
Clear().Send().Body().JSON(),
Send().Body().JSON("Hello Earth"),
Expect("Hello World"),
),
PtrStr("Not equal"), PtrStr(`expected: "Hello World"`), PtrStr(`actual: "\"Hello Earth\""`), nil, nil, nil, nil,
)
})
t.Run("specific", func(t *testing.T) {
ExpectError(t,
Do(
Post(s.URL),
Send().Body().JSON("Hello World"),
Send().Body().JSON("Hello Earth"),
Clear().Send().Body().JSON("Hello World"),
Expect("Hello World"),
),
PtrStr("Not equal"), PtrStr(`expected: "Hello World"`), PtrStr(`actual: "\"Hello Earth\""`), nil, nil, nil, nil,
)
})
}
func TestClearSendBody_Interface(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("all", func(t *testing.T) {
ExpectError(t,
Do(
Post(s.URL),
Send().Body().Interface("Hello World"),
Clear().Send().Body().Interface(),
Send().Body().Interface("Hello Earth"),
Expect("Hello World"),
),
PtrStr("Not equal"), PtrStr(`expected: "Hello World"`), PtrStr(`actual: "Hello Earth"`), nil, nil, nil, nil,
)
})
t.Run("specific", func(t *testing.T) {
ExpectError(t,
Do(
Post(s.URL),
Send().Body().Interface("Hello World"),
Send().Body().Interface("Hello Earth"),
Clear().Send().Body().Interface("Hello World"),
Expect("Hello World"),
),
PtrStr("Not equal"), PtrStr(`expected: "Hello World"`), PtrStr(`actual: "Hello Earth"`), nil, nil, nil, nil,
)
})
}
func TestClearSendBody_Final(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("Clear().Send().Body(value).JSON()", func(t *testing.T) {
ExpectError(t,
Do(Clear().Send().Body("Data").JSON()),
PtrStr("only usable with Clear().Send().Body() not with Clear().Send().Body(value)"),
)
})
t.Run("Clear().Send().Body(value).Interface()", func(t *testing.T) {
ExpectError(t,
Do(Clear().Send().Body("Data").Interface()),
PtrStr("only usable with Clear().Send().Body() not with Clear().Send().Body(value)"),
)
})
}
func TestClearSendBody_NotExistentStep(t *testing.T) {
s := EchoServer()
defer s.Close()
ExpectError(t,
Do(
Post(s.URL),
Send().Body("Hello World"),
Clear().Send().Body().JSON("Hello World"),
),
PtrStr(`unable to find a step with Send().Body().JSON("Hello World")`), PtrStr(`got these steps:`), PtrStr(`Send().Body("Hello World")`),
)
ExpectError(t,
Do(
Post(s.URL),
Send().Body("Hello World"),
Clear().Send().Body().JSON(),
),
PtrStr(`unable to find a step with Send().Body().JSON()`), PtrStr(`got these steps:`), PtrStr(`Send().Body("Hello World")`),
)
}