model: redirect mappings (RedirectTo, RedirectPermanent, RedirectKeepPath)
CI / test (push) Successful in 1m14s
CI / test (push) Successful in 1m14s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6753422f7a
commit
6663b268c8
2 files changed
+51
-2
No files matched your search
@@ -0,0 +1,25 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user