-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
context_test.go
57 lines (52 loc) · 982 Bytes
/
context_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
package goblin
import (
"context"
"testing"
)
func TestGetParam(t *testing.T) {
params := Params{
{
key: "id",
value: "123",
},
{
key: "name",
value: "john",
},
}
ctx := context.WithValue(context.Background(), ParamsKey, params)
ngCtx := context.WithValue(context.Background(), ParamsKey, "not a []Param")
cases := []struct {
name string
actual string
expected string
}{
{
name: "id_param",
actual: GetParam(ctx, "id"),
expected: "123",
},
{
name: "name_param",
actual: GetParam(ctx, "name"),
expected: "john",
},
{
name: "not_exist_param",
actual: GetParam(ctx, "not-exist-key"),
expected: "",
},
{
name: "param_value_wrong_type",
actual: GetParam(ngCtx, "ng ctx"),
expected: "",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if c.actual != c.expected {
t.Errorf("actual:%v expected:%v", c.actual, c.expected)
}
})
}
}