-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
67 lines (57 loc) · 1.27 KB
/
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
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
package poteto
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestWriteHeader(t *testing.T) {
w := httptest.NewRecorder()
resp := NewResponse(w).(*response)
tests := []struct {
name string
IsCommitted bool
expected int
}{
{"Test not committed case", false, http.StatusOK},
{"Test committed case", true, 0},
}
for _, it := range tests {
t.Run(it.name, func(t *testing.T) {
resp.IsCommitted = it.IsCommitted
resp.WriteHeader(http.StatusOK)
if resp.Status != http.StatusOK {
t.Errorf(
"Unmatched actual(%d) -> expected(%d)",
resp.Status,
it.expected,
)
}
})
}
}
func TestWrite(t *testing.T) {
w := httptest.NewRecorder()
resp := NewResponse(w).(*response)
tests := []struct {
name string
IsCommitted bool
b []byte
expected int
}{
{"write not committed response", false, []byte("Hello"), 5},
{"don't write committed reponse", true, []byte(""), 0},
}
for _, it := range tests {
t.Run(it.name, func(t *testing.T) {
resp.IsCommitted = it.IsCommitted
n, _ := resp.Write(it.b)
if n != it.expected {
t.Errorf(
"Unmatched actual(%d) -> expected(%d)",
n,
it.expected,
)
}
})
}
}