-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_test.go
More file actions
52 lines (48 loc) · 1.04 KB
/
Copy pathfetch_test.go
File metadata and controls
52 lines (48 loc) · 1.04 KB
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
package eutil
import (
"fmt"
"io"
"net/http"
"testing"
)
func TestFetch(t *testing.T) {
var (
url = "http://httpbin.org/post"
body = []byte(`{"key1": "value1", "key2": "value2"}`)
)
p := Fetch(http.MethodPost, url, body, nil, 0).
Then(func(res *http.Response) {
fmt.Println(res.StatusCode)
}).
Then(func(res *http.Response) {
b, _ := io.ReadAll(res.Body)
fmt.Println(string(b))
_ = res.Body.Close()
}).
Catch(func(res *http.Response, err error) {
fmt.Println(err.Error())
})
p.Await()
}
func BenchmarkFetch(b *testing.B) {
var (
url = "http://httpbin.org/post"
body = []byte(`{"key1": "value1", "key2": "value2"}`)
)
p := Fetch(http.MethodPost, url, body, nil, 0).
Then(func(res *http.Response) {
// fmt.Println(res.StatusCode)
}).
Then(func(res *http.Response) {
// b, _ := io.ReadAll(res.Body)
// fmt.Println(string(b))
// res.Body.Close()
}).
Catch(func(res *http.Response, err error) {
// fmt.Println(err.Error())
})
b.ResetTimer()
for i := 0; i < b.N; i++ {
p.Await()
}
}