Files
Reef/model/model_test.go
T
2026-10-27 04:06:42 -06:00

26 lines
973 B
Go

package model
import "testing"
func TestRedirectLocation(t *testing.T) {
cases := []struct {
m Mapping
uri string
want string
}{
{Mapping{RedirectTo: "https://new.example.com"}, "/a?b=1", "https://new.example.com"},
{Mapping{RedirectTo: "https://new.example.com", RedirectKeepPath: true}, "/a?b=1", "https://new.example.com/a?b=1"},
{Mapping{RedirectTo: "https://new.example.com/", RedirectKeepPath: true}, "/", "https://new.example.com/"},
{Mapping{RedirectTo: "https://new.example.com/base", RedirectKeepPath: true}, "/x/y", "https://new.example.com/base/x/y"},
{Mapping{RedirectTo: "https://new.example.com", RedirectKeepPath: true}, "", "https://new.example.com/"},
}
for _, c := range cases {
if got := c.m.RedirectLocation(c.uri); got != c.want {
t.Errorf("%+v %q: got %q, want %q", c.m, c.uri, got, c.want)
}
}
if (Mapping{}).IsRedirect() || !(Mapping{RedirectTo: "https://x"}).IsRedirect() {
t.Error("IsRedirect is wrong")
}
}