-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathgout_chunked_test.go
57 lines (45 loc) · 1.1 KB
/
gout_chunked_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
package gout
import (
"bytes"
"io"
"net"
"testing"
"time"
"github.com/guonaihong/gout/core"
"github.com/stretchr/testify/assert"
)
func testTcpSocket(out *bytes.Buffer, quit chan bool, t *testing.T) (addr string) {
addr = core.GetNoPortExists()
addr = ":" + addr
go func() {
defer close(quit)
listener, err := net.Listen("tcp", addr)
if err != nil {
t.Errorf("%v\n", err)
return
}
defer listener.Close()
conn, err := listener.Accept()
if err != nil {
t.Errorf("%v\n", err)
return
}
defer conn.Close()
if _, err = io.Copy(out, conn); err != nil {
t.Errorf("%v\n", err)
return
}
}()
return addr
}
func Test_Use_Chunked(t *testing.T) {
var out bytes.Buffer
quit := make(chan bool)
addr := testTcpSocket(&out, quit, t)
time.Sleep(time.Second / 100) //等待服务起好
// 这里超时返回错误, 原因tcp服务没有构造http返回报文
assert.Error(t, POST(addr).SetTimeout(time.Second/100).Chunked().SetBody("11111111111").Do())
<-quit
//time.Sleep(time.Second)
assert.NotEqual(t, bytes.Index(out.Bytes(), []byte("Transfer-Encoding: chunked")), -1)
}