MCPcopy Create free account
hub / github.com/go-chi/chi / TestTreeFindPattern

Function TestTreeFindPattern

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

Source from the content-addressed store, hash-verified

417}
418
419func TestTreeFindPattern(t *testing.T) {
420 hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
421 hStub2 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
422 hStub3 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
423
424 tr := &node{}
425 tr.InsertRoute(mGET, "/pages/*", hStub1)
426 tr.InsertRoute(mGET, "/articles/{id}/*", hStub2)
427 tr.InsertRoute(mGET, "/articles/{slug}/{uid}/*", hStub3)
428
429 if tr.findPattern("/pages") != false {
430 t.Errorf("find /pages failed")
431 }
432 if tr.findPattern("/pages*") != false {
433 t.Errorf("find /pages* failed - should be nil")
434 }
435 if tr.findPattern("/pages/*") == false {
436 t.Errorf("find /pages/* failed")
437 }
438 if tr.findPattern("/articles/{id}/*") == false {
439 t.Errorf("find /articles/{id}/* failed")
440 }
441 if tr.findPattern("/articles/{something}/*") == false {
442 t.Errorf("find /articles/{something}/* failed")
443 }
444 if tr.findPattern("/articles/{slug}/{uid}/*") == false {
445 t.Errorf("find /articles/{slug}/{uid}/* failed")
446 }
447}
448
449func debugPrintTree(parent int, i int, n *node, label byte) bool {
450 numEdges := 0

Callers

nothing calls this directly

Calls 3

InsertRouteMethod · 0.95
findPatternMethod · 0.95
HandlerFuncMethod · 0.80

Tested by

no test coverage detected