MCPcopy
hub / github.com/go-chi/chi / TestTreeRegexMatchWholeParam

Function TestTreeRegexMatchWholeParam

tree_test.go:387–415  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

385}
386
387func TestTreeRegexMatchWholeParam(t *testing.T) {
388 hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
389
390 rctx := NewRouteContext()
391 tr := &node{}
392 tr.InsertRoute(mGET, "/{id:[0-9]+}", hStub1)
393 tr.InsertRoute(mGET, "/{x:.+}/foo", hStub1)
394 tr.InsertRoute(mGET, "/{param:[0-9]*}/test", hStub1)
395
396 tests := []struct {
397 expectedHandler http.Handler
398 url string
399 }{
400 {url: "/13", expectedHandler: hStub1},
401 {url: "/a13", expectedHandler: nil},
402 {url: "/13.jpg", expectedHandler: nil},
403 {url: "/a13.jpg", expectedHandler: nil},
404 {url: "/a/foo", expectedHandler: hStub1},
405 {url: "//foo", expectedHandler: nil},
406 {url: "//test", expectedHandler: hStub1},
407 }
408
409 for _, tc := range tests {
410 _, _, handler := tr.FindRoute(rctx, mGET, tc.url)
411 if fmt.Sprintf("%v", tc.expectedHandler) != fmt.Sprintf("%v", handler) {
412 t.Errorf("url %v: expecting handler:%v , got:%v", tc.url, tc.expectedHandler, handler)
413 }
414 }
415}
416
417func TestTreeFindPattern(t *testing.T) {
418 hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

Callers

nothing calls this directly

Calls 4

InsertRouteMethod · 0.95
FindRouteMethod · 0.95
NewRouteContextFunction · 0.85
HandlerFuncMethod · 0.80

Tested by

no test coverage detected