diff --git a/route/matcher_test.go b/route/matcher_test.go index 76d69b4d5..59a068c90 100644 --- a/route/matcher_test.go +++ b/route/matcher_test.go @@ -34,32 +34,29 @@ func TestGlobMatcher(t *testing.T) { route *Route }{ // happy flows - {uri: "/foo", matches: true, route: getRoute("/foo")}, - {uri: "/fool", matches: true, route: getRoute("/foo?")}, - {uri: "/fool", matches: true, route: getRoute("/foo*")}, - {uri: "/fools", matches: true, route: getRoute("/foo*")}, - {uri: "/fools", matches: true, route: getRoute("/foo*")}, - {uri: "/foo/x/bar", matches: true, route: getRoute("/foo/*/bar")}, - {uri: "/foo/x/y/z/w/bar", matches: true, route: getRoute("/foo/**")}, - {uri: "/foo/x/y/z/w/bar", matches: true, route: getRoute("/foo/**/bar")}, + {uri: "/foo", matches: true, route: &Route{Path: "/foo"}}, + {uri: "/fool", matches: true, route: &Route{Path: "/foo?"}}, + {uri: "/fool", matches: true, route: &Route{Path: "/foo*"}}, + {uri: "/fools", matches: true, route: &Route{Path: "/foo*"}}, + {uri: "/fools", matches: true, route: &Route{Path: "/foo*"}}, + {uri: "/foo/x/bar", matches: true, route: &Route{Path: "/foo/*/bar"}}, + {uri: "/foo/x/y/z/w/bar", matches: true, route: &Route{Path: "/foo/**"}}, + {uri: "/foo/x/y/z/w/bar", matches: true, route: &Route{Path: "/foo/**/bar"}}, // error flows - {uri: "/fo", matches: false, route: getRoute("/foo")}, - {uri: "/fools", matches: false, route: getRoute("/foo")}, - {uri: "/fo", matches: false, route: getRoute("/foo*")}, - {uri: "/fools", matches: false, route: getRoute("/foo.*")}, - {uri: "/foo/x/y/z/w/baz", matches: false, route: getRoute("/foo/**/bar")}, + {uri: "/fo", matches: false, route: &Route{Path: "/foo"}}, + {uri: "/fools", matches: false, route: &Route{Path: "/foo"}}, + {uri: "/fo", matches: false, route: &Route{Path: "/foo*"}}, + {uri: "/fools", matches: false, route: &Route{Path: "/foo.*"}}, + {uri: "/foo/x/y/z/w/baz", matches: false, route: &Route{Path: "/foo/**/bar"}}, } for _, tt := range tests { t.Run(tt.uri, func(t *testing.T) { + tt.route.Glob = glob.MustCompile(tt.route.Path) if got, want := globMatcher(tt.uri, tt.route), tt.matches; got != want { t.Fatalf("got %v want %v", got, want) } }) } } - -func getRoute(path string) *Route { - return &Route{Path: path, Glob: glob.MustCompile(path)} -}