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

Function TestMuxPlain

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

Source from the content-addressed store, hash-verified

243}
244
245func TestMuxPlain(t *testing.T) {
246 r := NewRouter()
247 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
248 w.Write([]byte("bye"))
249 })
250 r.NotFound(func(w http.ResponseWriter, r *http.Request) {
251 w.WriteHeader(404)
252 w.Write([]byte("nothing here"))
253 })
254
255 ts := httptest.NewServer(r)
256 defer ts.Close()
257
258 if _, body := testRequest(t, ts, "GET", "/hi", nil); body != "bye" {
259 t.Fatal(body)
260 }
261 if _, body := testRequest(t, ts, "GET", "/nothing-here", nil); body != "nothing here" {
262 t.Fatal(body)
263 }
264}
265
266func TestMuxEmptyRoutes(t *testing.T) {
267 mux := NewRouter()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected