diff options
Diffstat (limited to 'src/pkg/http/cookie_test.go')
-rw-r--r-- | src/pkg/http/cookie_test.go | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/pkg/http/cookie_test.go b/src/pkg/http/cookie_test.go index 363c841bb..db0997040 100644 --- a/src/pkg/http/cookie_test.go +++ b/src/pkg/http/cookie_test.go @@ -6,6 +6,8 @@ package http import ( "bytes" + "fmt" + "json" "reflect" "testing" ) @@ -16,8 +18,12 @@ var writeSetCookiesTests = []struct { Raw string }{ { - []*Cookie{&Cookie{Name: "cookie-1", Value: "v$1", MaxAge: -1}}, - "Set-Cookie: Cookie-1=v$1\r\n", + []*Cookie{ + &Cookie{Name: "cookie-1", Value: "v$1"}, + &Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}, + }, + "Set-Cookie: cookie-1=v$1\r\n" + + "Set-Cookie: cookie-2=two; Max-Age=3600\r\n", }, } @@ -38,8 +44,8 @@ var writeCookiesTests = []struct { Raw string }{ { - []*Cookie{&Cookie{Name: "cookie-1", Value: "v$1", MaxAge: -1}}, - "Cookie: Cookie-1=v$1\r\n", + []*Cookie{&Cookie{Name: "cookie-1", Value: "v$1"}}, + "Cookie: cookie-1=v$1\r\n", }, } @@ -61,15 +67,23 @@ var readSetCookiesTests = []struct { }{ { Header{"Set-Cookie": {"Cookie-1=v$1"}}, - []*Cookie{&Cookie{Name: "Cookie-1", Value: "v$1", MaxAge: -1, Raw: "Cookie-1=v$1"}}, + []*Cookie{&Cookie{Name: "Cookie-1", Value: "v$1", Raw: "Cookie-1=v$1"}}, }, } +func toJSON(v interface{}) string { + b, err := json.Marshal(v) + if err != nil { + return fmt.Sprintf("%#v", v) + } + return string(b) +} + func TestReadSetCookies(t *testing.T) { for i, tt := range readSetCookiesTests { c := readSetCookies(tt.Header) if !reflect.DeepEqual(c, tt.Cookies) { - t.Errorf("#%d readSetCookies: have\n%#v\nwant\n%#v\n", i, c, tt.Cookies) + t.Errorf("#%d readSetCookies: have\n%s\nwant\n%s\n", i, toJSON(c), toJSON(tt.Cookies)) continue } } @@ -81,7 +95,7 @@ var readCookiesTests = []struct { }{ { Header{"Cookie": {"Cookie-1=v$1"}}, - []*Cookie{&Cookie{Name: "Cookie-1", Value: "v$1", MaxAge: -1, Raw: "Cookie-1=v$1"}}, + []*Cookie{&Cookie{Name: "Cookie-1", Value: "v$1"}}, }, } @@ -89,7 +103,7 @@ func TestReadCookies(t *testing.T) { for i, tt := range readCookiesTests { c := readCookies(tt.Header) if !reflect.DeepEqual(c, tt.Cookies) { - t.Errorf("#%d readCookies: have\n%#v\nwant\n%#v\n", i, c, tt.Cookies) + t.Errorf("#%d readCookies: have\n%s\nwant\n%s\n", i, toJSON(c), toJSON(tt.Cookies)) continue } } |