Files
ultrashorty/internal/redirect_test.go
T

32 lines
767 B
Go
Raw Normal View History

package internal
import "testing"
func TestRedirectsFind(t *testing.T) {
rs := Redirects{
{From: "/a", To: "https://example.com/a", StatusCode: 301},
{From: "/b", To: "https://example.com/b", StatusCode: 302},
}
if got := rs.Find("/b"); got == nil || got.To != "https://example.com/b" {
t.Errorf("Find(/b) = %+v", got)
}
if got := rs.Find("/missing"); got != nil {
t.Errorf("Find(/missing) = %+v, want nil", got)
}
if got := rs.Find("/A"); got != nil {
t.Errorf("Find is case-sensitive; Find(/A) = %+v, want nil", got)
}
}
func TestRedirectMatch(t *testing.T) {
r := &Redirect{From: "/x"}
if !r.Match("/x") {
t.Error("Match(/x) = false, want true")
}
if r.Match("/x/") {
t.Error("Match(/x/) = true, want false (exact match only)")
}
}