-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie_test.go
52 lines (43 loc) · 1.05 KB
/
cookie_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gerrittest
import (
"net/http"
"net/url"
. "gopkg.in/check.v1"
)
type CookieTest struct{}
var _ = Suite(&CookieTest{})
func (s *CookieTest) TestHostname(c *C) {
expected := map[string]string{
"127.0.0.1": "localhost",
"localhost": "localhost",
"foobar": "foobar",
}
for name, value := range expected {
c.Assert(hostname(&url.URL{Host: name}), Equals, value)
}
}
func (s *CookieTest) TestCookieJar_SetCookies(c *C) {
jar := NewCookieJar()
u := &url.URL{Host: "127.0.0.1"}
cookies := []*http.Cookie{{
Name: "foo",
Path: "/",
Value: "hello",
}}
expected := map[string]map[string]*http.Cookie{}
expected["localhost"] = map[string]*http.Cookie{}
expected["localhost"]["foo"] = cookies[0]
jar.SetCookies(u, cookies)
c.Assert(jar.cookies, DeepEquals, expected)
}
func (s *CookieTest) TestCookieJar_Cookies(c *C) {
jar := NewCookieJar()
u := &url.URL{Host: "127.0.0.1"}
cookies := []*http.Cookie{{
Name: "foo",
Path: "/",
Value: "hello",
}}
jar.SetCookies(u, cookies)
c.Assert(jar.Cookies(u), DeepEquals, cookies)
}