-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext_test.go
More file actions
42 lines (32 loc) · 924 Bytes
/
context_test.go
File metadata and controls
42 lines (32 loc) · 924 Bytes
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
package route
import (
"net/http"
"testing"
)
func TestContext(t *testing.T) {
r, _ := http.NewRequest("GET", "http://localhost:8080/", nil)
var testContext context
foo, _ := testContext.Get(r, "foo")
if len(foo) > 0 {
t.Fatal("Expected an empty string and got", foo)
}
params := make(map[string]string)
params["foo"] = "johndoe"
params["foo2"] = "42"
testContext.set(r, params)
if len(testContext.params[r]) != len(params) {
t.Fatal("Params map should contained", len(params), "elements. context params length =", len(testContext.params[r]))
}
id, _ := testContext.Get(r, "foo2")
if id != params["foo2"] {
t.Fatal("Expected", params["foo2"], "and got", id)
}
foo3, err := testContext.Get(r, "foo3")
if len(foo3) > 0 && err == nil {
t.Fatal("Expected an empty string and got", foo3)
}
testContext.clear(r)
if len(testContext.params) != 0 {
t.Fatal("Params map should be empty")
}
}