-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathresponse_test.go
89 lines (69 loc) · 1.76 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package lars
import (
"net/http"
"net/http/httptest"
"testing"
. "gopkg.in/go-playground/assert.v1"
)
// NOTES:
// - Run "go test" to run tests
// - Run "gocov test | gocov report" to report on test converage by file
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
//
// or
//
// -- may be a good idea to change to output path to somewherelike /tmp
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
//
func TestResponse(t *testing.T) {
l := New()
w := httptest.NewRecorder()
c := NewContext(l)
r := newResponse(w, c)
// SetWriter
r.SetWriter(w)
// Assert Write
Equal(t, w, r.Writer())
// Assert Header
NotEqual(t, nil, r.Header())
// WriteHeader
r.WriteHeader(http.StatusOK)
Equal(t, http.StatusOK, r.status)
Equal(t, true, r.committed)
// Already committed
r.WriteHeader(http.StatusTeapot)
NotEqual(t, http.StatusTeapot, r.Status())
// Status
r.status = http.StatusOK
Equal(t, http.StatusOK, r.Status())
// Write
info := "Information"
_, err := r.Write([]byte(info))
Equal(t, nil, err)
// Flush
r.Flush()
// Size
IsEqual(len(info), r.Size())
// WriteString
s := "lars"
n, err := r.WriteString(s)
Equal(t, err, nil)
Equal(t, n, 4)
//committed
Equal(t, true, r.Committed())
panicStr := "interface conversion: *httptest.ResponseRecorder is not http.Hijacker: missing method Hijack"
fnPanic := func() {
_, _, err := r.Hijack()
if err != nil {
panic(err)
}
}
PanicMatches(t, fnPanic, panicStr)
panicStr = "interface conversion: *httptest.ResponseRecorder is not http.CloseNotifier: missing method CloseNotify"
fnPanic = func() {
r.CloseNotify()
}
PanicMatches(t, fnPanic, panicStr)
// reset
r.reset(httptest.NewRecorder())
}