MCPcopy
hub / github.com/julienschmidt/httprouter / TestRouter

Function TestRouter

router_test.go:48–68  ·  router_test.go::TestRouter
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestRouter(t *testing.T) {
49 router := New()
50
51 routed := false
52 router.Handle(http.MethodGet, "/user/:name", func(w http.ResponseWriter, r *http.Request, ps Params) {
53 routed = true
54 want := Params{Param{"name", "gopher"}}
55 if !reflect.DeepEqual(ps, want) {
56 t.Fatalf("wrong wildcard values: want %v, got %v", want, ps)
57 }
58 })
59
60 w := new(mockResponseWriter)
61
62 req, _ := http.NewRequest(http.MethodGet, "/user/gopher", nil)
63 router.ServeHTTP(w, req)
64
65 if !routed {
66 t.Fatal("routing failed")
67 }
68}
69
70type handlerStruct struct {
71 handled *bool

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
HandleMethod · 0.80
ServeHTTPMethod · 0.45

Tested by

no test coverage detected