-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie_test.go
126 lines (121 loc) · 2.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package lightning
import (
"net/http"
"reflect"
"testing"
)
func TestCookie_Del(t *testing.T) {
type args struct {
key string
}
tests := []struct {
name string
cookies cookiesMap
args args
}{
{
name: "TestCookie_Del",
cookies: cookiesMap{"test": &http.Cookie{Name: "test", Value: "value"}},
args: args{key: "test"},
},
{
name: "TestCookie_Del_NotExist",
cookies: cookiesMap{},
args: args{key: "test"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cookies.del(tt.args.key)
if _, ok := tt.cookies[tt.args.key]; ok {
t.Errorf("del() failed to delete key %s", tt.args.key)
}
})
}
}
func TestCookie_Get(t *testing.T) {
type args struct {
key string
}
tests := []struct {
name string
cookies cookiesMap
args args
want *http.Cookie
}{
{
name: "TestCookie_Get",
cookies: cookiesMap{"test": &http.Cookie{Name: "test", Value: "test"}},
args: args{key: "test"},
want: &http.Cookie{Name: "test", Value: "test"},
},
{
name: "TestCookie_Get_NotExist",
cookies: cookiesMap{},
args: args{key: "test"},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cookies.get(tt.args.key); !reflect.DeepEqual(got, tt.want) {
t.Errorf("get() = %v, want %v", got, tt.want)
}
})
}
}
func TestCookie_Set(t *testing.T) {
type args struct {
key string
value string
}
tests := []struct {
name string
cookies cookiesMap
args args
}{
{
name: "TestCookie_Set",
cookies: cookiesMap{},
args: args{key: "test", value: "test"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cookies.set(tt.args.key, tt.args.value)
if _, ok := tt.cookies[tt.args.key]; !ok {
t.Errorf("set() failed to set key %s", tt.args.key)
}
if tt.cookies[tt.args.key].Value != tt.args.value {
t.Errorf("set() failed to set value %s for key %s", tt.args.value, tt.args.key)
}
})
}
}
func TestCookie_SetCustom(t *testing.T) {
type args struct {
cookie *http.Cookie
}
tests := []struct {
name string
cookies cookiesMap
args args
}{
{
name: "TestCookie_SetCustom",
cookies: cookiesMap{},
args: args{cookie: &http.Cookie{Name: "test", Value: "test"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cookies.setCustom(tt.args.cookie)
if _, ok := tt.cookies[tt.args.cookie.Name]; !ok {
t.Errorf("setCustom() failed to set key %s", tt.args.cookie.Name)
}
if tt.cookies[tt.args.cookie.Name] != tt.args.cookie {
t.Errorf("setCustom() failed to set value %s for key %s", tt.args.cookie.Value, tt.args.cookie.Name)
}
})
}
}