-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
61 lines (56 loc) · 1.18 KB
/
util_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
package restruct
import (
"context"
"net/http"
"testing"
)
func TestGetSetValues(t *testing.T) {
r := &http.Request{}
r2 := SetValue(r, "a", "1")
a := GetValue(r, "a")
if a == "1" {
t.Errorf("Want a to blank got 1 %v", a)
}
a = GetValue(r2, "a")
if a != "1" {
t.Errorf("Want a to be 1 got %v", a)
}
r = r2
r = SetValue(r, "a", "2")
r = SetValue(r, "b", "c")
vals := GetValues(r)
if vals["a"] != "2" {
t.Errorf("Want a to be 2 got %v", vals["a"])
}
if vals["b"] != "c" {
t.Errorf("Want b to be c got %v", vals["b"])
}
if x, ok := GetValue(r, "hello").(string); ok {
t.Errorf("X %v %v", x, ok)
}
}
func TestGetSetVals(t *testing.T) {
ctx := context.Background()
c2 := SetVal(ctx, "a", "1")
a := GetVal(ctx, "a")
if a == "1" {
t.Errorf("Want a to blank got 1 %v", a)
}
a = GetVal(c2, "a")
if a != "1" {
t.Errorf("Want a to be 1 got %v", a)
}
ctx = c2
ctx = SetVal(ctx, "a", "2")
ctx = SetVal(ctx, "b", "c")
vals := GetVals(ctx)
if vals["a"] != "2" {
t.Errorf("Want a to be 2 got %v", vals["a"])
}
if vals["b"] != "c" {
t.Errorf("Want b to be c got %v", vals["b"])
}
if x, ok := GetVal(ctx, "hello").(string); ok {
t.Errorf("X %v %v", x, ok)
}
}