-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathrequest_test.go
74 lines (60 loc) · 1.13 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
package HttpRequest
import (
"bytes"
"fmt"
"testing"
)
const localUrl = "http://localhost:8000"
var data = map[string]interface{}{
"name": "HttpRequest",
"version": "v1.0",
}
func TestGetRequest(t *testing.T) {
req := NewRequest()
test := []interface{}{
nil,
data,
"year=2018",
}
var resp *Response
var err error
for _, v := range test {
resp, err = req.Get(localUrl, v)
if err != nil {
t.Error(err)
return
}
}
if resp.StatusCode() != 200 {
t.Error("GET "+localUrl, "expected code 200", fmt.Sprintf("return code %d", resp.StatusCode()))
}
}
func TestPostRequest(t *testing.T) {
req := NewRequest()
test := []interface{}{
data,
bytes.NewReader([]byte{97}),
[]byte{97},
nil,
"github",
`{"name":"github","year":2018}`,
100,
int8(100),
int16(100),
int32(100),
int64(100),
"title=github&type=1",
}
var resp *Response
var err error
for _, v := range test {
resp, err = req.Post(localUrl, v)
if err != nil {
t.Error(err)
return
}
}
if resp.StatusCode() != 200 {
t.Error("GET "+localUrl, "expected code 200", fmt.Sprintf("return code %d", resp.StatusCode()))
}
}