forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrespx_test.go
48 lines (41 loc) · 1.18 KB
/
respx_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
package httpreq_test
import (
"fmt"
"testing"
"github.com/gookit/goutil/netutil/httpctype"
"github.com/gookit/goutil/netutil/httpreq"
"github.com/gookit/goutil/testutil/assert"
)
func TestRespX_String(t *testing.T) {
rx := httpreq.MustRespX(httpreq.Get(testSrvAddr + "/get"))
assert.NotNil(t, rx)
assert.Equal(t, 200, rx.StatusCode)
assert.True(t, rx.IsOk())
assert.True(t, rx.IsSuccessful())
assert.False(t, rx.IsFail())
assert.False(t, rx.IsEmptyBody())
assert.Equal(t, httpctype.JSON, rx.ContentType())
s := rx.String()
fmt.Println(s)
assert.StrContains(t, s, "GET")
rx = httpreq.MustRespX(httpreq.Post(testSrvAddr+"/post", "hi"))
assert.NotNil(t, rx)
assert.True(t, rx.IsOk())
s = rx.BodyString()
// fmt.Println(s)
assert.StrContains(t, s, `"hi"`)
}
func TestWrapResp(t *testing.T) {
rx, err := httpreq.WrapResp(httpreq.Get(testSrvAddr + "/get"))
assert.NoErr(t, err)
assert.NotNil(t, rx)
assert.Equal(t, 200, rx.StatusCode)
assert.True(t, rx.IsOk())
assert.True(t, rx.IsSuccessful())
assert.False(t, rx.IsFail())
assert.False(t, rx.IsEmptyBody())
assert.Equal(t, httpctype.JSON, rx.ContentType())
s := rx.String()
fmt.Println(s)
assert.StrContains(t, s, "GET")
}