forked from naoina/kocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
56 lines (51 loc) · 1.23 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
package kocha
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
func TestNewResponse(t *testing.T) {
rw := httptest.NewRecorder()
actual := NewResponse(rw)
expected := &Response{
ResponseWriter: rw,
ContentType: "",
StatusCode: http.StatusOK,
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}
func Test_Response_Cookies(t *testing.T) {
w := httptest.NewRecorder()
res := &Response{ResponseWriter: w}
actual := res.Cookies()
expected := res.cookies
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
cookie := &http.Cookie{Name: "fox", Value: "dog"}
res.cookies = append(res.cookies, cookie)
actual = res.Cookies()
expected = res.cookies
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}
func Test_Response_SetCookie(t *testing.T) {
w := httptest.NewRecorder()
res := &Response{
ResponseWriter: w,
}
cookie := &http.Cookie{
Name: "testCookie",
Value: "testCookieValue",
}
res.SetCookie(cookie)
actual := w.Header().Get("Set-Cookie")
expected := cookie.String()
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}