-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathcookie_test.go
62 lines (51 loc) · 1.31 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
53
54
55
56
57
58
59
60
61
62
package neo
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func makeTestRawCookie(key, value string) *http.Cookie {
return &http.Cookie{
Name: key,
Value: value,
Path: "/",
}
}
func makeTestResCookies() *Cookie {
return &Cookie{
"key1": makeTestRawCookie("key1", "value1"),
"key2": makeTestRawCookie("key2", "value2"),
}
}
func TestReqCookieGet(t *testing.T) {
cookies := Cookie{
"key": makeTestRawCookie("key", "value"),
}
assert.NotNil(t, cookies.Get("key"))
assert.Nil(t, cookies.Get("unknown"))
}
func TestResCookieGet(t *testing.T) {
cookies := makeTestResCookies()
assert.NotNil(t, cookies.Get("key1"))
assert.NotNil(t, cookies.Get("key2"))
assert.Nil(t, cookies.Get("key3"))
}
func TestResCookieSet(t *testing.T) {
cookies := makeTestResCookies()
cookies.Set("key3", "value3")
assert.NotNil(t, cookies.Get("key3"))
assert.Nil(t, cookies.Get("key4"))
}
func TestResCookieDel(t *testing.T) {
cookies := makeTestResCookies()
assert.NotNil(t, cookies.Get("key1"))
cookies.Del("key1")
assert.Nil(t, cookies.Get("key1"))
assert.NotNil(t, cookies.Get("key2"))
}
func TestResCookieSetCustom(t *testing.T) {
cookies := makeTestResCookies()
assert.Nil(t, cookies.Get("key3"))
cookies.SetCustom(makeTestRawCookie("key3", "value3"))
assert.NotNil(t, cookies.Get("key3"))
}