-
Notifications
You must be signed in to change notification settings - Fork 191
/
group_test.go
46 lines (38 loc) · 1004 Bytes
/
group_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
package goutil_test
import (
"fmt"
"testing"
"github.com/gookit/goutil"
"github.com/gookit/goutil/netutil/httpreq"
"github.com/gookit/goutil/structs"
"github.com/gookit/goutil/testutil"
"github.com/gookit/goutil/testutil/assert"
)
func TestNewErrGroup(t *testing.T) {
httpreq.SetTimeout(3000)
eg := goutil.NewErrGroup()
eg.Add(func() error {
resp, err := httpreq.Get(testSrvAddr + "/get")
if err != nil {
return err
}
fmt.Println(testutil.ParseBodyToReply(resp.Body))
return nil
}, func() error {
resp := httpreq.MustResp(httpreq.Post(testSrvAddr+"/post", "hi"))
fmt.Println(testutil.ParseBodyToReply(resp.Body))
return nil
})
err := eg.Wait()
assert.NoErr(t, err)
}
func TestQuickRun_methods(t *testing.T) {
qr := goutil.NewQuickRun()
qr.Add(func(ctx *structs.Data) error {
resp := httpreq.MustResp(httpreq.Get(testSrvAddr + "/get"))
rr := testutil.ParseBodyToReply(resp.Body)
assert.Eq(t, "GET", rr.Method)
return nil
})
assert.NoErr(t, qr.Run())
}