259
func TestClientSendsCookieFromJar(t *testing.T) {
260
tr := &recordingTransport{}
261
client := &Client{Transport: tr}
262
client.Jar = &TestJar{perURL: make(map[string][]*Cookie)}
263
us := "http://dummy.faketld/"
264
u, _ := url.Parse(us)
265
client.Jar.SetCookies(u, expectedCookies)
267
client.Get(us) // Note: doesn't hit network
268
matchReturnedCookies(t, expectedCookies, tr.req.Cookies())
270
client.Head(us) // Note: doesn't hit network
271
matchReturnedCookies(t, expectedCookies, tr.req.Cookies())
273
client.Post(us, "text/plain", strings.NewReader("body")) // Note: doesn't hit network
274
matchReturnedCookies(t, expectedCookies, tr.req.Cookies())
276
client.PostForm(us, url.Values{}) // Note: doesn't hit network
277
matchReturnedCookies(t, expectedCookies, tr.req.Cookies())
279
req, _ := NewRequest("GET", us, nil)
280
client.Do(req) // Note: doesn't hit network
281
matchReturnedCookies(t, expectedCookies, tr.req.Cookies())
259
284
// Just enough correctness for our redirect tests. Uses the URL.Host as the
260
285
// scope of all cookies.
261
286
type TestJar struct {