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

Function TestMuxSubrouterWildcardParam

mux_test.go:1653–1683  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1651}
1652
1653func TestMuxSubrouterWildcardParam(t *testing.T) {
1654 h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1655 fmt.Fprintf(w, "param:%v *:%v", URLParam(r, "param"), URLParam(r, "*"))
1656 })
1657
1658 r := NewRouter()
1659
1660 r.Get("/bare/{param}", h)
1661 r.Get("/bare/{param}/*", h)
1662
1663 r.Route("/case0", func(r Router) {
1664 r.Get("/{param}", h)
1665 r.Get("/{param}/*", h)
1666 })
1667
1668 ts := httptest.NewServer(r)
1669 defer ts.Close()
1670
1671 if _, body := testRequest(t, ts, "GET", "/bare/hi", nil); body != "param:hi *:" {
1672 t.Fatal(body)
1673 }
1674 if _, body := testRequest(t, ts, "GET", "/bare/hi/yes", nil); body != "param:hi *:yes" {
1675 t.Fatal(body)
1676 }
1677 if _, body := testRequest(t, ts, "GET", "/case0/hi", nil); body != "param:hi *:" {
1678 t.Fatal(body)
1679 }
1680 if _, body := testRequest(t, ts, "GET", "/case0/hi/yes", nil); body != "param:hi *:yes" {
1681 t.Fatal(body)
1682 }
1683}
1684
1685func TestMuxContextIsThreadSafe(t *testing.T) {
1686 router := NewRouter()

Callers

nothing calls this directly

Calls 7

GetMethod · 0.95
RouteMethod · 0.95
URLParamFunction · 0.85
NewRouterFunction · 0.85
HandlerFuncMethod · 0.80
CloseMethod · 0.80
testRequestFunction · 0.70

Tested by

no test coverage detected