Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package cookie_test |
||
2 | |||
3 | import ( |
||
4 | "net/http" |
||
5 | "net/url" |
||
6 | "testing" |
||
7 | |||
8 | "github.com/stefanoj3/dirstalk/pkg/scan/client/cookie" |
||
9 | "github.com/stretchr/testify/assert" |
||
10 | ) |
||
11 | |||
12 | func TestStatelessJarShouldWorkWithNilCookies(t *testing.T) { |
||
13 | assert.Nil(t, cookie.NewStatelessJar(nil).Cookies(nil)) |
||
14 | } |
||
15 | |||
16 | func TestStatelessJarShouldBeStateless(t *testing.T) { |
||
17 | cookies := []*http.Cookie{ |
||
18 | { |
||
19 | Name: "a_cookie_name", |
||
20 | Value: "a_cookie_value", |
||
21 | }, |
||
22 | } |
||
23 | |||
24 | jar := cookie.NewStatelessJar(cookies) |
||
25 | |||
26 | u, err := url.Parse("http://github.com/stefanoj3") |
||
27 | assert.NoError(t, err) |
||
28 | |||
29 | assert.Equal(t, cookies, jar.Cookies(u)) |
||
30 | |||
31 | jar.SetCookies( |
||
32 | u, |
||
33 | []*http.Cookie{ |
||
34 | { |
||
35 | Name: "another_cookie_name", |
||
36 | Value: "another_cookie_value", |
||
37 | }, |
||
38 | }, |
||
39 | ) |
||
40 | |||
41 | assert.Equal(t, cookies, jar.Cookies(u)) |
||
42 | } |
||
43 |