-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathasync_requests_test.go
148 lines (112 loc) · 2.79 KB
/
async_requests_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package gohttp
import "testing"
// TestAsyncGetRequest tests asynchronous GET request
func TestAsyncGetRequest(t *testing.T) {
t.Log("Sending GET async request... (expected http code: 200)")
req := NewRequest()
ch := make(chan *AsyncResponse)
for i := 0; i <= 100; i++ {
req.AsyncGet("http://httpbin.org/get", ch)
}
for i := 0; i <= 100; i++ {
aRes := <-ch
if aRes.Err != nil {
t.Error(aRes.Err)
}
if aRes.Resp.GetStatusCode() != 200 {
t.Error(
"For", "GET http://httpbin.org/get",
"expected", 200,
"got", aRes.Resp.GetStatusCode(),
)
}
}
}
// TestAsyncPostRequest tests asynchronous POST request
func TestAsyncPostRequest(t *testing.T) {
t.Log("Sending POST async request... (expected http code: 200)")
req := NewRequest()
ch := make(chan *AsyncResponse)
for i := 0; i <= 100; i++ {
req.AsyncPost("http://httpbin.org/post", ch)
}
for i := 0; i <= 100; i++ {
aRes := <-ch
if aRes.Err != nil {
t.Error(aRes.Err)
}
if aRes.Resp.GetStatusCode() != 200 {
t.Error(
"For", "POST http://httpbin.org/post",
"expected", 200,
"got", aRes.Resp.GetStatusCode(),
)
}
}
}
// TestAsyncPutRequest tests asynchronous PUT request
func TestAsyncPutRequest(t *testing.T) {
t.Log("Sending PUT async request... (expected http code: 200)")
req := NewRequest()
ch := make(chan *AsyncResponse)
for i := 0; i <= 100; i++ {
req.AsyncPut("http://httpbin.org/put", ch)
}
for i := 0; i <= 100; i++ {
aRes := <-ch
if aRes.Err != nil {
t.Error(aRes.Err)
}
if aRes.Resp.GetStatusCode() != 200 {
t.Error(
"For", "PUT http://httpbin.org/put",
"expected", 200,
"got", aRes.Resp.GetStatusCode(),
)
}
}
}
// TestAsyncPatchRequest tests asynchronous PATCH request
func TestAsyncPatchRequest(t *testing.T) {
t.Log("Sending PATCH async request... (expected http code: 200)")
req := NewRequest()
ch := make(chan *AsyncResponse)
for i := 0; i <= 100; i++ {
req.AsyncPatch("http://httpbin.org/patch", ch)
}
for i := 0; i <= 100; i++ {
aRes := <-ch
if aRes.Err != nil {
t.Error(aRes.Err)
}
if aRes.Resp.GetStatusCode() != 200 {
t.Error(
"For", "PATCH http://httpbin.org/patch",
"expected", 200,
"got", aRes.Resp.GetStatusCode(),
)
}
}
}
// TestAsyncDeleteRequest tests asynchronous DELETE request
func TestAsyncDeleteRequest(t *testing.T) {
t.Log("Sending DELETE async request... (expected http code: 200)")
req := NewRequest()
ch := make(chan *AsyncResponse)
for i := 0; i <= 100; i++ {
req.AsyncDelete("http://httpbin.org/delete", ch)
}
for i := 0; i <= 100; i++ {
aRes := <-ch
if aRes.Err != nil {
t.Error(aRes.Err)
}
if aRes.Resp.GetStatusCode() != 200 {
t.Error(
"For", "DELETE http://httpbin.org/delete",
"expected", 200,
"got", aRes.Resp.GetStatusCode(),
)
}
}
}