-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest_test.go
52 lines (48 loc) · 1.01 KB
/
request_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
package tcp_test
import (
"io"
"io/ioutil"
"strconv"
"strings"
"testing"
"github.com/matryer/is"
"github.com/rvflash/tcp"
)
func TestNewRequest(t *testing.T) {
var (
are = is.New(t)
dt = []struct {
seg string
body io.Reader
segment string
resp []byte
}{
{segment: tcp.SYN},
{seg: tcp.ACK, segment: tcp.ACK},
{seg: tcp.SYN, segment: tcp.SYN},
{seg: tcp.FIN, segment: tcp.FIN},
{seg: "NOP", segment: "NOP"},
{seg: tcp.ACK, segment: tcp.ACK, body: strings.NewReader(msg), resp: []byte(msg)},
}
req *tcp.Request
b []byte
err error
)
for i, tt := range dt {
tt := tt
t.Run("#"+strconv.Itoa(i), func(t *testing.T) {
req = tcp.NewRequest(tt.seg, tt.body)
are.Equal(req.Segment, tt.segment)
if tt.body == nil {
are.True(req.Body == nil)
} else {
b, err = ioutil.ReadAll(req.Body)
are.NoErr(err)
are.Equal(b, tt.resp)
}
})
}
}
func TestRequest_Context(t *testing.T) {
is.New(t).True(tcp.NewRequest(tcp.SYN, nil).Context() != nil)
}