]> Cypherpunks repositories - gostls13.git/commitdiff
http: fix cookie_test
authorRuss Cox <rsc@golang.org>
Mon, 7 Mar 2011 19:45:45 +0000 (14:45 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 7 Mar 2011 19:45:45 +0000 (14:45 -0500)
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

index 827f232c0065297acd7cf317aac36e323b1a8daf..db09970406b0eac802f9337638756211cf38bc2e 100644 (file)
@@ -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
                }
        }