-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_data_test.go
111 lines (107 loc) · 2.12 KB
/
context_data_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
package lightning
import (
"reflect"
"testing"
)
func TestContextData_Del(t *testing.T) {
type args struct {
key string
}
tests := []struct {
name string
c contextData
args args
want interface{}
}{
{
name: "delete existing key",
c: contextData{"foo": "bar"},
args: args{"foo"},
want: contextData{},
},
{
name: "delete non-existing key",
c: contextData{"foo": "bar"},
args: args{"baz"},
want: contextData{"foo": "bar"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.c.del(tt.args.key)
if !reflect.DeepEqual(tt.c, tt.want) {
t.Errorf("del() = %v, want %v", tt.c, tt.want)
}
})
}
}
func TestContextData_Get(t *testing.T) {
type args struct {
key string
}
tests := []struct {
name string
c contextData
args args
want interface{}
}{
{
name: "get existing key",
c: contextData{"foo": "bar"},
args: args{"foo"},
want: "bar",
},
{
name: "get non-existing key",
c: contextData{"foo": "bar"},
args: args{"baz"},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.c.get(tt.args.key); !reflect.DeepEqual(got, tt.want) {
t.Errorf("get() = %v, want %v", got, tt.want)
}
})
}
}
func TestContextData_Set(t *testing.T) {
type args struct {
key string
value interface{}
}
tests := []struct {
name string
c contextData
args args
want interface{}
}{
{
name: "set new key-value pair in empty contextData",
c: contextData{},
args: args{"foo", "bar"},
want: contextData{"foo": "bar"},
},
{
name: "set new key-value pair in non-empty contextData",
c: contextData{"foo": "bar"},
args: args{"baz", 123},
want: contextData{"foo": "bar", "baz": 123},
},
{
name: "set existing key to new value",
c: contextData{"foo": "bar"},
args: args{"foo", 123},
want: contextData{"foo": 123},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.c.set(tt.args.key, tt.args.value)
if !reflect.DeepEqual(tt.c, tt.want) {
t.Errorf("set() = %v, want %v", tt.c, tt.want)
}
})
}
}