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

Function TestMuxMissingParams

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

Source from the content-addressed store, hash-verified

1530}
1531
1532func TestMuxMissingParams(t *testing.T) {
1533 r := NewRouter()
1534 r.Get(`/user/{userId:\d+}`, func(w http.ResponseWriter, r *http.Request) {
1535 userID := URLParam(r, "userId")
1536 w.Write([]byte(fmt.Sprintf("userId = '%s'", userID)))
1537 })
1538 r.NotFound(func(w http.ResponseWriter, r *http.Request) {
1539 w.WriteHeader(404)
1540 w.Write([]byte("nothing here"))
1541 })
1542
1543 ts := httptest.NewServer(r)
1544 defer ts.Close()
1545
1546 if _, body := testRequest(t, ts, "GET", "/user/123", nil); body != "userId = '123'" {
1547 t.Fatal(body)
1548 }
1549 if _, body := testRequest(t, ts, "GET", "/user/", nil); body != "nothing here" {
1550 t.Fatal(body)
1551 }
1552}
1553
1554func TestMuxWildcardRoute(t *testing.T) {
1555 handler := func(w http.ResponseWriter, r *http.Request) {}

Callers

nothing calls this directly

Calls 8

GetMethod · 0.95
NotFoundMethod · 0.95
NewRouterFunction · 0.85
URLParamFunction · 0.85
CloseMethod · 0.80
testRequestFunction · 0.70
WriteMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected