-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathtee_test.go
40 lines (37 loc) · 1.13 KB
/
tee_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
package tigertonic
import (
"net/http"
"net/url"
"testing"
)
func TestTeeHeaderResponseWriter(t *testing.T) {
w0 := &testResponseWriter{}
w := NewTeeHeaderResponseWriter(w0)
r, _ := http.NewRequest("GET", "http://example.com/foo", nil)
Marshaled(func(*url.URL, http.Header) (int, http.Header, *testResponse, error) {
return http.StatusOK, http.Header{"X-Foo": []string{"bar"}}, &testResponse{"bar"}, nil
}).ServeHTTP(w, r)
if w0.StatusCode != w.StatusCode {
t.Fatal(w.StatusCode)
}
if w0.Header().Get("X-Foo") != w.Header().Get("X-Foo") {
t.Fatal(w.Header())
}
}
func TestTeeResponseWriter(t *testing.T) {
w0 := &testResponseWriter{}
w := NewTeeResponseWriter(w0)
r, _ := http.NewRequest("GET", "http://example.com/foo", nil)
Marshaled(func(*url.URL, http.Header) (int, http.Header, *testResponse, error) {
return http.StatusOK, http.Header{"X-Foo": []string{"bar"}}, &testResponse{"bar"}, nil
}).ServeHTTP(w, r)
if w0.StatusCode != w.StatusCode {
t.Fatal(w.StatusCode)
}
if w0.Header().Get("X-Foo") != w.Header().Get("X-Foo") {
t.Fatal(w.Header())
}
if w0.Body.String() != w.Body.String() {
t.Fatal(w.Body.String())
}
}