From 792ff386043cd40604ff34bfaab4879c375f7a04 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 7 Mar 2011 14:45:45 -0500 Subject: [PATCH] http: fix cookie_test Was only breaking on some dashboard builds because not all run the network tests. R=bradfitzgo, bradfitzwork CC=golang-dev https://golang.org/cl/4240086 --- src/pkg/http/cookie_test.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/pkg/http/cookie_test.go b/src/pkg/http/cookie_test.go index 827f232c00..db09970406 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,7 +44,7 @@ var writeCookiesTests = []struct { Raw string }{ { - []*Cookie{&Cookie{Name: "cookie-1", Value: "v$1", MaxAge: -1}}, + []*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 } } -- 2.50.0