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

Function TestMuxMounts

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

Source from the content-addressed store, hash-verified

206}
207
208func TestMuxMounts(t *testing.T) {
209 r := NewRouter()
210
211 r.Get("/{hash}", func(w http.ResponseWriter, r *http.Request) {
212 v := URLParam(r, "hash")
213 w.Write([]byte(fmt.Sprintf("/%s", v)))
214 })
215
216 r.Route("/{hash}/share", func(r Router) {
217 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
218 v := URLParam(r, "hash")
219 w.Write([]byte(fmt.Sprintf("/%s/share", v)))
220 })
221 r.Get("/{network}", func(w http.ResponseWriter, r *http.Request) {
222 v := URLParam(r, "hash")
223 n := URLParam(r, "network")
224 w.Write([]byte(fmt.Sprintf("/%s/share/%s", v, n)))
225 })
226 })
227
228 m := NewRouter()
229 m.Mount("/sharing", r)
230
231 ts := httptest.NewServer(m)
232 defer ts.Close()
233
234 if _, body := testRequest(t, ts, "GET", "/sharing/aBc", nil); body != "/aBc" {
235 t.Fatal(body)
236 }
237 if _, body := testRequest(t, ts, "GET", "/sharing/aBc/share", nil); body != "/aBc/share" {
238 t.Fatal(body)
239 }
240 if _, body := testRequest(t, ts, "GET", "/sharing/aBc/share/twitter", nil); body != "/aBc/share/twitter" {
241 t.Fatal(body)
242 }
243}
244
245func TestMuxPlain(t *testing.T) {
246 r := NewRouter()

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected