@@ -15,22 +15,57 @@ import (
15
15
"github.com/valyala/bytebufferpool"
16
16
)
17
17
18
+ func TestRequestCopyTo (t * testing.T ) {
19
+ var req Request
20
+
21
+ // empty copy
22
+ testRequestCopyTo (t , & req )
23
+
24
+ // init
25
+ expectedContentType := "application/x-www-form-urlencoded; charset=UTF-8"
26
+ expectedHost := "test.com"
27
+ expectedBody := "0123=56789"
28
+ s := fmt .Sprintf ("POST / HTTP/1.1\r \n Host: %s\r \n Content-Type: %s\r \n Content-Length: %d\r \n \r \n %s" ,
29
+ expectedHost , expectedContentType , len (expectedBody ), expectedBody )
30
+ br := bufio .NewReader (bytes .NewBufferString (s ))
31
+ if err := req .Read (br ); err != nil {
32
+ t .Fatalf ("unexpected error: %s" , err )
33
+ }
34
+ testRequestCopyTo (t , & req )
35
+
36
+ }
37
+
18
38
func TestResponseCopyTo (t * testing.T ) {
19
- resp := & Response {}
20
- copyResp := & Response {}
39
+ var resp Response
40
+
41
+ // empty copy
42
+ testResponseCopyTo (t , & resp )
21
43
22
44
// init resp
23
45
resp .laddr = zeroTCPAddr
24
46
resp .SkipBody = true
25
47
resp .Header .SetStatusCode (200 )
26
48
resp .SetBodyString ("test" )
49
+ testResponseCopyTo (t , & resp )
27
50
28
- resp .CopyTo (copyResp )
51
+ }
52
+
53
+ func testRequestCopyTo (t * testing.T , src * Request ) {
54
+ var dst Request
55
+ src .CopyTo (& dst )
29
56
30
- if ! reflect .DeepEqual (resp , copyResp ) {
31
- t .Fatal ( "ResponseCopyTo fail" )
57
+ if ! reflect .DeepEqual (* src , dst ) {
58
+ t .Fatalf ( "RequestCopyTo fail, src: \n %+v \n dst: \n %+v \n " , * src , dst )
32
59
}
60
+ }
33
61
62
+ func testResponseCopyTo (t * testing.T , src * Response ) {
63
+ var dst Response
64
+ src .CopyTo (& dst )
65
+
66
+ if ! reflect .DeepEqual (* src , dst ) {
67
+ t .Fatalf ("ResponseCopyTo fail, src: \n %+v\n dst: \n %+v\n " , * src , dst )
68
+ }
34
69
}
35
70
36
71
func TestResponseBodyStreamDeflate (t * testing.T ) {
0 commit comments