...
Source file
src/goji.io/mux_test.go
Documentation: goji.io
1 package goji
2
3 import (
4 "context"
5 "net/http"
6 "testing"
7
8 "goji.io/internal"
9 )
10
11 func TestMuxExistingPath(t *testing.T) {
12 m := NewMux()
13 handler := func(w http.ResponseWriter, r *http.Request) {
14 ctx := r.Context()
15 if path := ctx.Value(internal.Path).(string); path != "/" {
16 t.Errorf("expected path=/, got %q", path)
17 }
18 }
19 m.HandleFunc(boolPattern(true), handler)
20 w, r := wr()
21 ctx := context.WithValue(context.Background(), internal.Path, "/hello")
22 r = r.WithContext(ctx)
23 m.ServeHTTP(w, r)
24 }
25
26 func TestSubMuxExistingPath(t *testing.T) {
27 m := SubMux()
28 handler := func(w http.ResponseWriter, r *http.Request) {
29 ctx := r.Context()
30 if path := ctx.Value(internal.Path).(string); path != "/hello" {
31 t.Errorf("expected path=/hello, got %q", path)
32 }
33 }
34 m.HandleFunc(boolPattern(true), handler)
35 w, r := wr()
36 ctx := context.WithValue(context.Background(), internal.Path, "/hello")
37 r = r.WithContext(ctx)
38 m.ServeHTTP(w, r)
39 }
40
View as plain text