为了账号安全,请及时绑定邮箱和手机立即绑定

使用 cookie 测试请求

使用 cookie 测试请求

Go
德玛西亚99 2021-09-10 10:52:33
我写了一个 cookie getter 和 setter。现在我想测试它,并编写了以下测试函数。func TestAuthorizationReader(t *testing.T) {    tw := httptest.NewServer(testWriter())    tr := httptest.NewServer(Use(testReader()))    defer tw.Close()    defer tr.Close()    c := &http.Client{}    rs, err := c.Get(tw.URL)    assert.NoError(t, err, "Should not contain any error")    // Assign cookie to client    url, err := rs.Location()    fmt.Print(url)    assert.NoError(t, err, "Should not contain any error")    //c.Jar.SetCookies(url, rs.Cookies())}测试在第二部分失败,作为我得到的输出消息- FAIL: TestAuthorizationReader (0.05s) Location:       logged_test.go:64 Error:          No error is expected but got http: no Location header in response Messages:       Should not contain any error我无法获得 URL 位置指针,我在这里做错了什么?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 223 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号