-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathbase_head_test.go
More file actions
50 lines (40 loc) · 1.16 KB
/
base_head_test.go
File metadata and controls
50 lines (40 loc) · 1.16 KB
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
package grequests
import (
"context"
"net/url"
"testing"
"github.com/stretchr/testify/suite"
)
type HeadSuite struct {
suite.Suite
}
func (s *HeadSuite) TestHeadRequest() {
srv := newHeadServer()
defer srv.Close()
resp, err := Head(context.Background(), srv.URL)
s.Require().NoError(err)
s.True(resp.Ok)
s.Equal("text/plain", resp.Header.Get("Content-Type"))
}
func (s *HeadSuite) TestHeadSessionCookies() {
srv := newCookieSetServer()
defer srv.Close()
session := NewSession(nil)
_, err := session.Head(context.Background(), srv.URL+"?one=two", &RequestOptions{})
s.Require().NoError(err)
_, err = session.Head(context.Background(), srv.URL+"?two=three", &RequestOptions{})
s.Require().NoError(err)
_, err = session.Head(context.Background(), srv.URL+"?three=four", &RequestOptions{})
s.Require().NoError(err)
cookieURL, err := url.Parse(srv.URL)
s.Require().NoError(err)
s.Len(session.HTTPClient.Jar.Cookies(cookieURL), 3)
}
func (s *HeadSuite) TestHeadInvalidURLSession() {
session := NewSession(nil)
_, err := session.Head(context.Background(), "%../dir/", nil)
s.Error(err)
}
func TestHeadSuite(t *testing.T) {
suite.Run(t, new(HeadSuite))
}