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

Function TestMuxMatch

mux_test.go:1807–1843  ·  mux_test.go::TestMuxMatch
(t *testing.T)

Source from the content-addressed store, hash-verified

1805}
1806
1807func TestMuxMatch(t *testing.T) {
1808 r := NewRouter()
1809 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
1810 w.Header().Set("X-Test", "yes")
1811 w.Write([]byte("bye"))
1812 })
1813 r.Route("/articles", func(r Router) {
1814 r.Get("/{id}", func(w http.ResponseWriter, r *http.Request) {
1815 id := URLParam(r, "id")
1816 w.Header().Set("X-Article", id)
1817 w.Write([]byte("article:" + id))
1818 })
1819 })
1820 r.Route("/users", func(r Router) {
1821 r.Head("/{id}", func(w http.ResponseWriter, r *http.Request) {
1822 w.Header().Set("X-User", "-")
1823 w.Write([]byte("user"))
1824 })
1825 r.Get("/{id}", func(w http.ResponseWriter, r *http.Request) {
1826 id := URLParam(r, "id")
1827 w.Header().Set("X-User", id)
1828 w.Write([]byte("user:" + id))
1829 })
1830 })
1831
1832 tctx := NewRouteContext()
1833
1834 tctx.Reset()
1835 if r.Match(tctx, "GET", "/users/1") == false {
1836 t.Fatal("expecting to find match for route:", "GET", "/users/1")
1837 }
1838
1839 tctx.Reset()
1840 if r.Match(tctx, "HEAD", "/articles/10") == true {
1841 t.Fatal("not expecting to find match for route:", "HEAD", "/articles/10")
1842 }
1843}
1844
1845func TestMuxMatch_HasBasePath(t *testing.T) {
1846 r := NewRouter()

Callers

nothing calls this directly

Calls 9

GetMethod · 0.95
RouteMethod · 0.95
HeadMethod · 0.95
NewRouterFunction · 0.85
URLParamFunction · 0.85
NewRouteContextFunction · 0.85
WriteMethod · 0.65
ResetMethod · 0.65
MatchMethod · 0.65

Tested by

no test coverage detected