33 lines
993 B
Go
33 lines
993 B
Go
package playletser
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeBannerURL(t *testing.T) {
|
|
cases := map[string]string{
|
|
"/detail/hqtqxdqe": "/detail/hqtqxdqe/",
|
|
"/detail/hqtqxdqe/": "/detail/hqtqxdqe/",
|
|
" /play/abc ": "/play/abc/",
|
|
"/detail/abc?from=banner": "/detail/abc/?from=banner",
|
|
"/": "/",
|
|
"": "",
|
|
"https://example.com/a": "https://example.com/a",
|
|
"//cdn.example.com/a": "//cdn.example.com/a",
|
|
"/static/images/a.png": "/static/images/a.png",
|
|
}
|
|
for in, want := range cases {
|
|
if got := normalizeBannerURL(in); got != want {
|
|
t.Errorf("normalizeBannerURL(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestActiveHomeBannersNormalizesURL(t *testing.T) {
|
|
got := ActiveHomeBanners([]HomeBannerData{
|
|
{ID: 1, URL: "/detail/abc", Status: true},
|
|
{ID: 2, URL: "/detail/off", Status: false},
|
|
})
|
|
if len(got) != 1 || got[0].URL != "/detail/abc/" {
|
|
t.Fatalf("unexpected banners: %+v", got)
|
|
}
|
|
}
|