Skip to content

Commit 3509745

Browse files
committed
Add tests for all four StrictSlash cases
1 parent bac1372 commit 3509745

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

mux_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,52 @@ func TestStrictSlash(t *testing.T) {
620620
r.StrictSlash(true)
621621

622622
tests := []routeTest{
623+
{
624+
title: "Redirect path without slash",
625+
route: r.NewRoute().Path("/111/"),
626+
request: newRequest("GET", "http://localhost/111"),
627+
vars: map[string]string{},
628+
host: "",
629+
path: "/111/",
630+
shouldMatch: true,
631+
shouldRedirect: true,
632+
},
633+
{
634+
title: "Do not redirect path with slash",
635+
route: r.NewRoute().Path("/111/"),
636+
request: newRequest("GET", "http://localhost/111/"),
637+
vars: map[string]string{},
638+
host: "",
639+
path: "/111/",
640+
shouldMatch: true,
641+
shouldRedirect: false,
642+
},
643+
{
644+
title: "Redirect path with slash",
645+
route: r.NewRoute().Path("/111"),
646+
request: newRequest("GET", "http://localhost/111/"),
647+
vars: map[string]string{},
648+
host: "",
649+
path: "/111",
650+
shouldMatch: true,
651+
shouldRedirect: true,
652+
},
653+
{
654+
title: "Do not redirect path without slash",
655+
route: r.NewRoute().Path("/111"),
656+
request: newRequest("GET", "http://localhost/111"),
657+
vars: map[string]string{},
658+
host: "",
659+
path: "/111",
660+
shouldMatch: true,
661+
shouldRedirect: false,
662+
},
623663
{
624664
title: "Ignore StrictSlash for path prefix",
625665
route: r.NewRoute().PathPrefix("/static/"),
626666
request: newRequest("GET", "http://localhost/static/logo.png"),
627667
vars: map[string]string{},
668+
host: "",
628669
path: "/static/",
629670
shouldMatch: true,
630671
shouldRedirect: false,

0 commit comments

Comments
 (0)