snapshot of https://github.com/go-chi/chi.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Test / test (1.24.x, ubuntu-latest) (push) Successful in 2m56s
Test / test (1.25.x, ubuntu-latest) (push) Successful in 2m15s
Test / test (1.26.x, ubuntu-latest) (push) Successful in 2m23s
Test / test (1.27.x, ubuntu-latest) (push) Failing after 3m56s
Test / test (1.24.x, windows-latest) (push) Has been cancelled
Test / test (1.25.x, windows-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
Test / test (1.27.x, windows-latest) (push) Has been cancelled
Some checks failed
Test / test (1.24.x, ubuntu-latest) (push) Successful in 2m56s
Test / test (1.25.x, ubuntu-latest) (push) Successful in 2m15s
Test / test (1.26.x, ubuntu-latest) (push) Successful in 2m23s
Test / test (1.27.x, ubuntu-latest) (push) Failing after 3m56s
Test / test (1.24.x, windows-latest) (push) Has been cancelled
Test / test (1.25.x, windows-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
Test / test (1.27.x, windows-latest) (push) Has been cancelled
This commit is contained in:
69
middleware/url_format_test.go
Normal file
69
middleware/url_format_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
func TestURLFormat(t *testing.T) {
|
||||
r := chi.NewRouter()
|
||||
|
||||
r.Use(URLFormat)
|
||||
|
||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("nothing here"))
|
||||
})
|
||||
|
||||
r.Route("/samples/articles/samples.{articleID}", func(r chi.Router) {
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
articleID := chi.URLParam(r, "articleID")
|
||||
w.Write([]byte(articleID))
|
||||
})
|
||||
})
|
||||
|
||||
r.Route("/articles/{articleID}", func(r chi.Router) {
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
articleID := chi.URLParam(r, "articleID")
|
||||
w.Write([]byte(articleID))
|
||||
})
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(r)
|
||||
defer ts.Close()
|
||||
|
||||
if _, resp := testRequest(t, ts, "GET", "/articles/1.json", nil); resp != "1" {
|
||||
t.Fatal(resp)
|
||||
}
|
||||
if _, resp := testRequest(t, ts, "GET", "/articles/1.xml", nil); resp != "1" {
|
||||
t.Fatal(resp)
|
||||
}
|
||||
if _, resp := testRequest(t, ts, "GET", "/samples/articles/samples.1.json", nil); resp != "1" {
|
||||
t.Fatal(resp)
|
||||
}
|
||||
if _, resp := testRequest(t, ts, "GET", "/samples/articles/samples.1.xml", nil); resp != "1" {
|
||||
t.Fatal(resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLFormatInSubRouter(t *testing.T) {
|
||||
r := chi.NewRouter()
|
||||
|
||||
r.Route("/articles/{articleID}", func(r chi.Router) {
|
||||
r.Use(URLFormat)
|
||||
r.Get("/subroute", func(w http.ResponseWriter, r *http.Request) {
|
||||
articleID := chi.URLParam(r, "articleID")
|
||||
w.Write([]byte(articleID))
|
||||
})
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(r)
|
||||
defer ts.Close()
|
||||
|
||||
if _, resp := testRequest(t, ts, "GET", "/articles/1/subroute.json", nil); resp != "1" {
|
||||
t.Fatal(resp)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user