-
Notifications
You must be signed in to change notification settings - Fork 2
/
response_internal_test.go
71 lines (67 loc) · 1.38 KB
/
response_internal_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package tcp
import (
"testing"
"github.com/matryer/is"
)
func TestResponseWriter_Write(t *testing.T) {
var (
are = is.New(t)
dt = []struct {
msg string
len, size int
}{
{msg: "hi", len: 2, size: 2},
{msg: " ", len: 1, size: 3},
{msg: "world!", len: 6, size: 9},
{msg: "\n", len: 1, size: 10},
}
w = newWriter(NewRecorder())
n int
err error
)
// buffer not used yet
are.Equal(w.Size(), noWritten)
// writes into
for _, tt := range dt {
tt := tt
t.Run(tt.msg, func(t *testing.T) {
n, err = w.Write([]byte(tt.msg))
are.NoErr(err)
are.Equal(n, tt.len) // len mismatch
are.Equal(w.Size(), tt.size) // size mismatch
})
}
// closes it.
are.NoErr(w.Close())
}
func TestResponseWriter_WriteString(t *testing.T) {
var (
are = is.New(t)
dt = []struct {
msg string
len, size int
}{
{msg: "hi", len: 2, size: 2},
{msg: " ", len: 1, size: 3},
{msg: "world!", len: 6, size: 9},
{msg: "\n", len: 1, size: 10},
}
w = newWriter(NewRecorder())
n int
err error
)
// buffer not used yet
are.Equal(w.Size(), noWritten)
// writes into
for _, tt := range dt {
tt := tt
t.Run(tt.msg, func(t *testing.T) {
n, err = w.WriteString(tt.msg)
are.NoErr(err)
are.Equal(n, tt.len) // len mismatch
are.Equal(w.Size(), tt.size) // size mismatch
})
}
// closes it.
are.NoErr(w.Close())
}