-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrequest_test.go
108 lines (86 loc) · 2.24 KB
/
request_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
package httptest
import (
"net/url"
"testing"
"github.com/stretchr/testify/require"
)
func Test_HTML_Headers_Dont_Overwrite_App_Headers(t *testing.T) {
r := require.New(t)
w := New(App())
w.Headers["foo"] = "bar"
req := w.HTML("/")
req.Headers["foo"] = "baz"
r.Equal("baz", req.Headers["foo"])
r.Equal("bar", w.Headers["foo"])
}
func Test_Get(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/get")
r.Equal("/get", req.URL)
res := req.Get()
r.Equal(201, res.Code)
r.Contains(res.Body.String(), "METHOD:GET")
r.Contains(res.Body.String(), "Hello from Get!")
}
func Test_Delete(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/delete")
r.Equal("/delete", req.URL)
res := req.Delete()
r.Contains(res.Body.String(), "METHOD:DELETE")
r.Contains(res.Body.String(), "Goodbye")
}
func Test_Post_Struct(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/post")
res := req.Post(User{Name: "Mark"})
r.Contains(res.Body.String(), "METHOD:POST")
r.Contains(res.Body.String(), "NAME:Mark")
}
func Test_Post_Struct_Pointer(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/post")
res := req.Post(&User{Name: "Mark"})
r.Contains(res.Body.String(), "METHOD:POST")
r.Contains(res.Body.String(), "NAME:Mark")
}
func Test_Post_Values(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/post")
vals := url.Values{}
vals.Add("name", "Mark")
res := req.Post(vals)
r.Contains(res.Body.String(), "METHOD:POST")
r.Contains(res.Body.String(), "NAME:Mark")
}
func Test_Put(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/put")
res := req.Put(User{Name: "Mark"})
r.Contains(res.Body.String(), "METHOD:PUT")
r.Contains(res.Body.String(), "NAME:Mark")
}
func Test_Put_Struct_Pointer(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/put")
res := req.Put(&User{Name: "Mark"})
r.Contains(res.Body.String(), "METHOD:PUT")
r.Contains(res.Body.String(), "NAME:Mark")
}
func Test_Put_Values(t *testing.T) {
r := require.New(t)
w := New(App())
req := w.HTML("/put")
vals := url.Values{}
vals.Add("name", "Mark")
res := req.Put(vals)
r.Contains(res.Body.String(), "METHOD:PUT")
r.Contains(res.Body.String(), "NAME:Mark")
}