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

Function TestMuxEmptyParams

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

Source from the content-addressed store, hash-verified

1510}
1511
1512func TestMuxEmptyParams(t *testing.T) {
1513 r := NewRouter()
1514 r.Get(`/users/{x}/{y}/{z}`, func(w http.ResponseWriter, r *http.Request) {
1515 x := URLParam(r, "x")
1516 y := URLParam(r, "y")
1517 z := URLParam(r, "z")
1518 w.Write([]byte(fmt.Sprintf("%s-%s-%s", x, y, z)))
1519 })
1520
1521 ts := httptest.NewServer(r)
1522 defer ts.Close()
1523
1524 if _, body := testRequest(t, ts, "GET", "/users/a/b/c", nil); body != "a-b-c" {
1525 t.Fatal(body)
1526 }
1527 if _, body := testRequest(t, ts, "GET", "/users///c", nil); body != "--c" {
1528 t.Fatal(body)
1529 }
1530}
1531
1532func TestMuxMissingParams(t *testing.T) {
1533 r := NewRouter()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected