mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
021b040a1e
commit
792ff38604
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue