-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresponse_test.go
39 lines (35 loc) · 942 Bytes
/
response_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
package exposed
import (
"bufio"
"bytes"
"fmt"
"testing"
)
func TestResponseMarshalUnmarshal(t *testing.T) {
var buf bytes.Buffer
resp := AcquireResponse()
bw := bufio.NewWriter(&buf)
for i := 0; i < 10; i++ {
value := fmt.Sprintf("payload %d", i)
resp.SwapPayload([]byte(value))
if err := resp.WriteResponse(bw); err != nil {
t.Fatalf("unexpected error when writing response: %s", err)
}
}
if err := bw.Flush(); err != nil {
t.Fatalf("unexpected error when flushing response: %s", err)
}
ReleaseResponse(resp)
resp1 := AcquireResponse()
br := bufio.NewReader(&buf)
for i := 0; i < 10; i++ {
value := fmt.Sprintf("payload %d", i)
if err := resp1.ReadResponse(br); err != nil {
t.Fatalf("unexpected error when reading response: %s", err)
}
if string(resp1.Payload()) != value {
t.Fatalf("unexpected request payload read: %q. Expecting %q", resp1.Payload(), value)
}
}
ReleaseResponse(resp1)
}