-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_helper.go
39 lines (30 loc) · 857 Bytes
/
test_helper.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 test
import (
"net/http"
"net/http/httptest"
)
type header struct {
Key string
Value string
}
func ExecRequest(app http.Handler, method, path string, headers ...header) *httptest.ResponseRecorder {
req := httptest.NewRequest(method, path, nil)
for _, h := range headers {
req.Header.Add(h.Key, h.Value)
}
w := httptest.NewRecorder()
app.ServeHTTP(w, req)
return w
}
type CustomerResWriter struct{}
func (m *CustomerResWriter) Header() (h http.Header) {
return http.Header{}
}
func (m *CustomerResWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (m *CustomerResWriter) WriteString(s string) (n int, err error) {
return len(s), nil
}
func (m *CustomerResWriter) WriteHeader(int) {}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++