package web
import "testing"
// Repo was read with req.PathValue in the outermost middleware, where
// the router has not set it: path values live on the request the mux
// passes DOWN, a copy that middleware never sees. Every render recorded
// before this carried an empty repo — 61 of 61 rows in the analytics
// store — which made every number unattributable on a fleet where
// repository size is the dominant cost.
func TestRepoOfPath(t *testing.T) {
for path, want := range map[string]string{
"/r/pikchr": "pikchr",
"/r/pikchr/": "pikchr",
"/r/fossil/timeline": "fossil",
"/r/fossil/checkin/abc123": "fossil",
"/r/spatialite%2Dtools/docs": "spatialite-tools", // the router would unescape it
"/fleet": "",
"/fleet/ops": "",
"/": "",
"": "",
"/r/": "",
} {
if got := repoOfPath(path, nil); got != want {
t.Errorf("repoOfPath(%q) = %q, want %q", path, got, want)
}
}
}