-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmux_test.go
39 lines (35 loc) · 943 Bytes
/
mux_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
package goji
import (
"context"
"net/http"
"testing"
"goji.io/internal"
)
func TestMuxExistingPath(t *testing.T) {
m := NewMux()
handler := func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if path := ctx.Value(internal.Path).(string); path != "/" {
t.Errorf("expected path=/, got %q", path)
}
}
m.HandleFunc(boolPattern(true), handler)
w, r := wr()
ctx := context.WithValue(context.Background(), internal.Path, "/hello")
r = r.WithContext(ctx)
m.ServeHTTP(w, r)
}
func TestSubMuxExistingPath(t *testing.T) {
m := SubMux()
handler := func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if path := ctx.Value(internal.Path).(string); path != "/hello" {
t.Errorf("expected path=/hello, got %q", path)
}
}
m.HandleFunc(boolPattern(true), handler)
w, r := wr()
ctx := context.WithValue(context.Background(), internal.Path, "/hello")
r = r.WithContext(ctx)
m.ServeHTTP(w, r)
}