-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
expect_body_test.go
126 lines (108 loc) · 2.46 KB
/
expect_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package hit_test
import (
"testing"
. "github.com/Eun/go-hit"
)
func TestExpectBody_Equal(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("bytes", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String(`Hello World`),
Expect().Body().Bytes().Equal([]byte("Hello World")),
)
})
t.Run("string", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Body().String().Equal(`Hello World`),
)
})
t.Run("slice (JSON)", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String(`["A", "B"]`),
Expect().Body().JSON().Equal([]string{"A", "B"}),
)
})
t.Run("int", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String("8"),
Expect().Body().Int().Equal(8),
)
})
}
func TestExpectBody_NotEqual(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("bytes", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String(`Hello World`),
Expect().Body().Bytes().NotEqual([]byte("Hello Universe")),
)
})
t.Run("string", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Body().String().NotEqual(`Hello Universe`),
)
})
t.Run("int", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String("8"),
Expect().Body().Int().NotEqual(6),
)
})
t.Run("slice (JSON)", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String(`["A", "B"]`),
Expect().Body().JSON().NotEqual([]string{"A", "B", "C"}),
)
})
}
func TestExpectBody_Contains(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("string", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Body().String().Contains(`World`),
)
})
t.Run("slice (JSON)", func(t *testing.T) {
ExpectError(t,
Do(
Post(s.URL),
Send().Body().String(`"Hello World"`),
Expect().Body().JSON().Contains([]string{"Hello World"}),
),
PtrStr(`"Hello World" does not contain []string{`), PtrStr(`"Hello World",`), PtrStr("}"),
)
})
}
func TestExpectBody_NotContains(t *testing.T) {
s := EchoServer()
defer s.Close()
t.Run("string", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Body().String().NotContains(`Universe`),
)
})
t.Run("slice (JSON)", func(t *testing.T) {
Test(t,
Post(s.URL),
Send().Body().String(`"Hello World"`),
Expect().Body().JSON().NotContains([]string{"Hello Universe"}),
)
})
}