Files
web_hghl_server/pub/common/webpath/paths_test.go
T
2026-10-26 16:28:14 +08:00

43 lines
1.0 KiB
Go

package webpath
import "testing"
func TestNormalizePublicURL(t *testing.T) {
t.Parallel()
tests := []struct {
raw string
want string
allow bool
}{
{"https://91jxporn.com/avtopic/", "https://91jxporn.com/video/all", true},
{"https://91jxporn.com/dh/", "https://91jxporn.com/nav", true},
{"https://91jxporn.com/richtext?title=test", "https://91jxporn.com/richtext?title=test", true},
{"https://91jxporn.com/topic/", "", false},
{"https://91jxporn.com/tag/all/", "", false},
{"https://91jxporn.com/useragreement/", "", false},
}
for _, tt := range tests {
got, ok := NormalizePublicURL(tt.raw)
if ok != tt.allow {
t.Fatalf("NormalizePublicURL(%q) allow = %v, want %v", tt.raw, ok, tt.allow)
}
if !tt.allow {
continue
}
if got != tt.want {
t.Fatalf("NormalizePublicURL(%q) = %q, want %q", tt.raw, got, tt.want)
}
}
}
func TestNormalizePublicPath(t *testing.T) {
t.Parallel()
got, ok := NormalizePublicPath("/avtopic/")
if !ok || got != "/video/all" {
t.Fatalf("NormalizePublicPath(/avtopic/) = %q, %v", got, ok)
}
}