-
Notifications
You must be signed in to change notification settings - Fork 1
/
fast_test.go
109 lines (98 loc) · 2.01 KB
/
fast_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
package fasthttp
import (
_ "net/http/pprof"
"testing"
)
var (
res *Response
err error
)
func TestGet(t *testing.T) {
res, err = NewClient().Get("http://httpbin.org/get")
if err == nil {
t.Log(string(res.Body))
}
t.Log(err)
res, err = NewClient().
AddParam("param1", "param1").
AddParams(
NewParams().
Set("param2", "param2").
Set("param3", "param3")).
AddHeader("header1", "header1").
AddHeaders(
NewHeaders().
Set("header2", "header2").
Set("header3", "header3")).
AddCookie("cookie1", "cookie1").
AddCookies(
NewCookies().
Set("cookie1", "cookie1").
Set("cookie2", "cookie2")).
Get("http://httpbin.org/get?am=999")
if err == nil {
t.Log(string(res.Body))
}
t.Log(err)
}
func TestPost(t *testing.T) {
res, err = NewClient().Post("http://httpbin.org/post")
if err == nil {
t.Log(string(res.Body))
}
t.Log(err)
res, err = NewClient().
AddBodyStruct(
struct {
Request string `json:"request" form:"request"`
Num int `json:"num"`
}{
Request: "test",
Num: 1,
},
).
AddHeader("header1", "header1").
AddHeaders(
NewHeaders().
Set("header2", "header2").
Set("header3", "header3"),
//"content-type": "application/json",
).
AddCookie("cookie1", "cookie1").
AddCookies(NewCookies().
Set("cookie1", "cookie1").
Set("cookie2", "cookie2")).
Post("http://httpbin.org/post")
if err == nil {
t.Log(string(res.Body))
}
t.Log(err)
}
func TestSendFile(t *testing.T) {
res, err = NewClient().
AddFile("a", "/Users/chuwt/Downloads/test.jpg").
AddFiles(
NewFiles().
Set("b", "/Users/chuwt/Downloads/test.jpg"),
).
SendFile("http://httpbin.org/post")
if err == nil {
t.Log(string(res.Body))
}
t.Log(err)
}
func TestSyncPool(t *testing.T) {
sp := NewClientPool()
res, err := sp.Get().(*Client).Get("http://httpbin.org/get")
if err != nil {
t.Error(err)
return
}
t.Log(string(res.Body))
}
func TestMapper(t *testing.T) {
adder := NewHeaders().
Set("a", "b").
Set("c", "d")
t.Log(adder)
}