summaryrefslogtreecommitdiff
path: root/src/pkg/http/cookie_test.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-05-23 09:45:29 +0200
committerOndřej Surý <ondrej@sury.org>2011-05-23 09:45:29 +0200
commit63d29fefab5290dc96e0a03ff70603aefa995887 (patch)
tree95da0105686f9aba568a72e7a8ebd580a4fda20e /src/pkg/http/cookie_test.go
parentad811fbb8897a9a3063274e927133915941f1dca (diff)
downloadgolang-63d29fefab5290dc96e0a03ff70603aefa995887.tar.gz
Imported Upstream version 2011.05.22upstream-weekly/2011.05.22
Diffstat (limited to 'src/pkg/http/cookie_test.go')
-rw-r--r--src/pkg/http/cookie_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pkg/http/cookie_test.go b/src/pkg/http/cookie_test.go
index a3ae85cd6..13c9fff4a 100644
--- a/src/pkg/http/cookie_test.go
+++ b/src/pkg/http/cookie_test.go
@@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"json"
+ "os"
"reflect"
"testing"
)
@@ -43,14 +44,55 @@ func TestWriteSetCookies(t *testing.T) {
}
}
+type headerOnlyResponseWriter Header
+
+func (ho headerOnlyResponseWriter) Header() Header {
+ return Header(ho)
+}
+
+func (ho headerOnlyResponseWriter) Write([]byte) (int, os.Error) {
+ panic("NOIMPL")
+}
+
+func (ho headerOnlyResponseWriter) WriteHeader(int) {
+ panic("NOIMPL")
+}
+
+func TestSetCookie(t *testing.T) {
+ m := make(Header)
+ SetCookie(headerOnlyResponseWriter(m), &Cookie{Name: "cookie-1", Value: "one", Path: "/restricted/"})
+ SetCookie(headerOnlyResponseWriter(m), &Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600})
+ if l := len(m["Set-Cookie"]); l != 2 {
+ t.Fatalf("expected %d cookies, got %d", 2, l)
+ }
+ if g, e := m["Set-Cookie"][0], "cookie-1=one; Path=/restricted/"; g != e {
+ t.Errorf("cookie #1: want %q, got %q", e, g)
+ }
+ if g, e := m["Set-Cookie"][1], "cookie-2=two; Max-Age=3600"; g != e {
+ t.Errorf("cookie #2: want %q, got %q", e, g)
+ }
+}
+
var writeCookiesTests = []struct {
Cookies []*Cookie
Raw string
}{
{
+ []*Cookie{},
+ "",
+ },
+ {
[]*Cookie{&Cookie{Name: "cookie-1", Value: "v$1"}},
"Cookie: cookie-1=v$1\r\n",
},
+ {
+ []*Cookie{
+ &Cookie{Name: "cookie-1", Value: "v$1"},
+ &Cookie{Name: "cookie-2", Value: "v$2"},
+ &Cookie{Name: "cookie-3", Value: "v$3"},
+ },
+ "Cookie: cookie-1=v$1; cookie-2=v$2; cookie-3=v$3\r\n",
+ },
}
func TestWriteCookies(t *testing.T) {