"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tree_test.go" between
gin-1.7.6.tar.gz and gin-1.7.7.tar.gz

About: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API (with much better performance).

tree_test.go  (gin-1.7.6):tree_test.go  (gin-1.7.7)
skipping to change at line 36 skipping to change at line 36
nilHandler bool nilHandler bool
route string route string
ps Params ps Params
} }
func getParams() *Params { func getParams() *Params {
ps := make(Params, 0, 20) ps := make(Params, 0, 20)
return &ps return &ps
} }
func getSkippedNodes() *[]skippedNode {
ps := make([]skippedNode, 0, 20)
return &ps
}
func checkRequests(t *testing.T, tree *node, requests testRequests, unescapes .. .bool) { func checkRequests(t *testing.T, tree *node, requests testRequests, unescapes .. .bool) {
unescape := false unescape := false
if len(unescapes) >= 1 { if len(unescapes) >= 1 {
unescape = unescapes[0] unescape = unescapes[0]
} }
for _, request := range requests { for _, request := range requests {
value := tree.getValue(request.path, getParams(), unescape) value := tree.getValue(request.path, getParams(), getSkippedNodes (), unescape)
if value.handlers == nil { if value.handlers == nil {
if !request.nilHandler { if !request.nilHandler {
t.Errorf("handle mismatch for route '%s': Expecte d non-nil handle", request.path) t.Errorf("handle mismatch for route '%s': Expecte d non-nil handle", request.path)
} }
} else if request.nilHandler { } else if request.nilHandler {
t.Errorf("handle mismatch for route '%s': Expected nil ha ndle", request.path) t.Errorf("handle mismatch for route '%s': Expected nil ha ndle", request.path)
} else { } else {
value.handlers[0](nil) value.handlers[0](nil)
if fakeHandlerValue != request.route { if fakeHandlerValue != request.route {
skipping to change at line 160 skipping to change at line 165
"/files/:dir/*filepath", "/files/:dir/*filepath",
"/doc/", "/doc/",
"/doc/go_faq.html", "/doc/go_faq.html",
"/doc/go1.html", "/doc/go1.html",
"/info/:user/public", "/info/:user/public",
"/info/:user/project/:project", "/info/:user/project/:project",
"/info/:user/project/golang", "/info/:user/project/golang",
"/aa/*xx", "/aa/*xx",
"/ab/*xx", "/ab/*xx",
"/:cc", "/:cc",
"/c1/:dd/e",
"/c1/:dd/e1",
"/:cc/cc", "/:cc/cc",
"/:cc/:dd/ee", "/:cc/:dd/ee",
"/:cc/:dd/:ee/ff", "/:cc/:dd/:ee/ff",
"/:cc/:dd/:ee/:ff/gg", "/:cc/:dd/:ee/:ff/gg",
"/:cc/:dd/:ee/:ff/:gg/hh", "/:cc/:dd/:ee/:ff/:gg/hh",
"/get/test/abc/", "/get/test/abc/",
"/get/:param/abc/", "/get/:param/abc/",
"/something/:paramname/thirdthing", "/something/:paramname/thirdthing",
"/something/secondthing/test", "/something/secondthing/test",
"/get/abc", "/get/abc",
skipping to change at line 241 skipping to change at line 248
{"/aa", false, "/:cc", Params{Param{Key: "cc", Value: "aa"}}}, {"/aa", false, "/:cc", Params{Param{Key: "cc", Value: "aa"}}},
{"/aaa", false, "/:cc", Params{Param{Key: "cc", Value: "aaa"}}}, {"/aaa", false, "/:cc", Params{Param{Key: "cc", Value: "aaa"}}},
{"/aaa/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "aaa "}}}, {"/aaa/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "aaa "}}},
{"/ab", false, "/:cc", Params{Param{Key: "cc", Value: "ab"}}}, {"/ab", false, "/:cc", Params{Param{Key: "cc", Value: "ab"}}},
{"/abb", false, "/:cc", Params{Param{Key: "cc", Value: "abb"}}}, {"/abb", false, "/:cc", Params{Param{Key: "cc", Value: "abb"}}},
{"/abb/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "abb "}}}, {"/abb/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "abb "}}},
{"/allxxxx", false, "/:cc", Params{Param{Key: "cc", Value: "allxx xx"}}}, {"/allxxxx", false, "/:cc", Params{Param{Key: "cc", Value: "allxx xx"}}},
{"/alldd", false, "/:cc", Params{Param{Key: "cc", Value: "alldd"} }}, {"/alldd", false, "/:cc", Params{Param{Key: "cc", Value: "alldd"} }},
{"/all/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "all "}}}, {"/all/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "all "}}},
{"/a/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "a"}}} , {"/a/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "a"}}} ,
{"/c1/d/e", false, "/c1/:dd/e", Params{Param{Key: "dd", Value: "d
"}}},
{"/c1/d/e1", false, "/c1/:dd/e1", Params{Param{Key: "dd", Value:
"d"}}},
{"/c1/d/ee", false, "/:cc/:dd/ee", Params{Param{Key: "cc", Value:
"c1"}, Param{Key: "dd", Value: "d"}}},
{"/cc/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "cc"} }}, {"/cc/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "cc"} }},
{"/ccc/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "ccc "}}}, {"/ccc/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "ccc "}}},
{"/deedwjfs/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "deedwjfs"}}}, {"/deedwjfs/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: "deedwjfs"}}},
{"/acllcc/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: " acllcc"}}}, {"/acllcc/cc", false, "/:cc/cc", Params{Param{Key: "cc", Value: " acllcc"}}},
{"/get/test/abc/", false, "/get/test/abc/", nil}, {"/get/test/abc/", false, "/get/test/abc/", nil},
{"/get/te/abc/", false, "/get/:param/abc/", Params{Param{Key: "pa ram", Value: "te"}}}, {"/get/te/abc/", false, "/get/:param/abc/", Params{Param{Key: "pa ram", Value: "te"}}},
{"/get/testaa/abc/", false, "/get/:param/abc/", Params{Param{Key: "param", Value: "testaa"}}}, {"/get/testaa/abc/", false, "/get/:param/abc/", Params{Param{Key: "param", Value: "testaa"}}},
{"/get/xx/abc/", false, "/get/:param/abc/", Params{Param{Key: "pa ram", Value: "xx"}}}, {"/get/xx/abc/", false, "/get/:param/abc/", Params{Param{Key: "pa ram", Value: "xx"}}},
{"/get/tt/abc/", false, "/get/:param/abc/", Params{Param{Key: "pa ram", Value: "tt"}}}, {"/get/tt/abc/", false, "/get/:param/abc/", Params{Param{Key: "pa ram", Value: "tt"}}},
{"/get/a/abc/", false, "/get/:param/abc/", Params{Param{Key: "par am", Value: "a"}}}, {"/get/a/abc/", false, "/get/:param/abc/", Params{Param{Key: "par am", Value: "a"}}},
skipping to change at line 580 skipping to change at line 590
"/aa", "/aa",
"/a/", "/a/",
"/admin", "/admin",
"/admin/:category", "/admin/:category",
"/admin/:category/:page", "/admin/:category/:page",
"/doc", "/doc",
"/doc/go_faq.html", "/doc/go_faq.html",
"/doc/go1.html", "/doc/go1.html",
"/no/a", "/no/a",
"/no/b", "/no/b",
"/api/hello/:name", "/api/:page/:name",
"/api/hello/:name/bar/",
"/api/bar/:name",
"/api/baz/foo",
"/api/baz/foo/bar",
"/blog/:p",
"/posts/:b/:c",
"/posts/b/:c/d/",
} }
for _, route := range routes { for _, route := range routes {
recv := catchPanic(func() { recv := catchPanic(func() {
tree.addRoute(route, fakeHandler(route)) tree.addRoute(route, fakeHandler(route))
}) })
if recv != nil { if recv != nil {
t.Fatalf("panic inserting route '%s': %v", route, recv) t.Fatalf("panic inserting route '%s': %v", route, recv)
} }
} }
skipping to change at line 606 skipping to change at line 623
"/src", "/src",
"/x/", "/x/",
"/y", "/y",
"/0/go/", "/0/go/",
"/1/go", "/1/go",
"/a", "/a",
"/admin/", "/admin/",
"/admin/config/", "/admin/config/",
"/admin/config/permissions/", "/admin/config/permissions/",
"/doc/", "/doc/",
"/admin/static/",
"/admin/cfg/",
"/admin/cfg/users/",
"/api/hello/x/bar",
"/api/baz/foo/",
"/api/baz/bax/",
"/api/bar/huh/",
"/api/baz/foo/bar/",
"/api/world/abc/",
"/blog/pp/",
"/posts/b/c/d",
} }
for _, route := range tsrRoutes { for _, route := range tsrRoutes {
value := tree.getValue(route, nil, false) value := tree.getValue(route, nil, getSkippedNodes(), false)
if value.handlers != nil { if value.handlers != nil {
t.Fatalf("non-nil handler for TSR route '%s", route) t.Fatalf("non-nil handler for TSR route '%s", route)
} else if !value.tsr { } else if !value.tsr {
t.Errorf("expected TSR recommendation for route '%s'", ro ute) t.Errorf("expected TSR recommendation for route '%s'", ro ute)
} }
} }
noTsrRoutes := [...]string{ noTsrRoutes := [...]string{
"/", "/",
"/no", "/no",
"/no/", "/no/",
"/_", "/_",
"/_/", "/_/",
"/api/world/abc", "/api",
"/api/",
"/api/hello/x/foo",
"/api/baz/foo/bad",
"/foo/p/p",
} }
for _, route := range noTsrRoutes { for _, route := range noTsrRoutes {
value := tree.getValue(route, nil, false) value := tree.getValue(route, nil, getSkippedNodes(), false)
if value.handlers != nil { if value.handlers != nil {
t.Fatalf("non-nil handler for No-TSR route '%s", route) t.Fatalf("non-nil handler for No-TSR route '%s", route)
} else if value.tsr { } else if value.tsr {
t.Errorf("expected no TSR recommendation for route '%s'", route) t.Errorf("expected no TSR recommendation for route '%s'", route)
} }
} }
} }
func TestTreeRootTrailingSlashRedirect(t *testing.T) { func TestTreeRootTrailingSlashRedirect(t *testing.T) {
tree := &node{} tree := &node{}
recv := catchPanic(func() { recv := catchPanic(func() {
tree.addRoute("/:test", fakeHandler("/:test")) tree.addRoute("/:test", fakeHandler("/:test"))
}) })
if recv != nil { if recv != nil {
t.Fatalf("panic inserting test route: %v", recv) t.Fatalf("panic inserting test route: %v", recv)
} }
value := tree.getValue("/", nil, false) value := tree.getValue("/", nil, getSkippedNodes(), false)
if value.handlers != nil { if value.handlers != nil {
t.Fatalf("non-nil handler") t.Fatalf("non-nil handler")
} else if value.tsr { } else if value.tsr {
t.Errorf("expected no TSR recommendation") t.Errorf("expected no TSR recommendation")
} }
} }
func TestTreeFindCaseInsensitivePath(t *testing.T) { func TestTreeFindCaseInsensitivePath(t *testing.T) {
tree := &node{} tree := &node{}
skipping to change at line 824 skipping to change at line 857
tree := &node{} tree := &node{}
tree.addRoute("/", fakeHandler("/")) tree.addRoute("/", fakeHandler("/"))
tree.addRoute("/:page", fakeHandler("/:page")) tree.addRoute("/:page", fakeHandler("/:page"))
// set invalid node type // set invalid node type
tree.children[0].nType = 42 tree.children[0].nType = 42
// normal lookup // normal lookup
recv := catchPanic(func() { recv := catchPanic(func() {
tree.getValue("/test", nil, false) tree.getValue("/test", nil, getSkippedNodes(), false)
}) })
if rs, ok := recv.(string); !ok || rs != panicMsg { if rs, ok := recv.(string); !ok || rs != panicMsg {
t.Fatalf("Expected panic '"+panicMsg+"', got '%v'", recv) t.Fatalf("Expected panic '"+panicMsg+"', got '%v'", recv)
} }
// case-insensitive lookup // case-insensitive lookup
recv = catchPanic(func() { recv = catchPanic(func() {
tree.findCaseInsensitivePath("/test", true) tree.findCaseInsensitivePath("/test", true)
}) })
if rs, ok := recv.(string); !ok || rs != panicMsg { if rs, ok := recv.(string); !ok || rs != panicMsg {
t.Fatalf("Expected panic '"+panicMsg+"', got '%v'", recv) t.Fatalf("Expected panic '"+panicMsg+"', got '%v'", recv)
} }
} }
func TestTreeInvalidParamsType(t *testing.T) {
tree := &node{}
tree.wildChild = true
tree.children = append(tree.children, &node{})
tree.children[0].nType = 2
// set invalid Params type
params := make(Params, 0, 0)
// try to trigger slice bounds out of range with capacity 0
tree.getValue("/test", &params, getSkippedNodes(), false)
}
func TestTreeWildcardConflictEx(t *testing.T) { func TestTreeWildcardConflictEx(t *testing.T) {
conflicts := [...]struct { conflicts := [...]struct {
route string route string
segPath string segPath string
existPath string existPath string
existSegPath string existSegPath string
}{ }{
{"/who/are/foo", "/foo", `/who/are/\*you`, `/\*you`}, {"/who/are/foo", "/foo", `/who/are/\*you`, `/\*you`},
{"/who/are/foo/", "/foo/", `/who/are/\*you`, `/\*you`}, {"/who/are/foo/", "/foo/", `/who/are/\*you`, `/\*you`},
{"/who/are/foo/bar", "/foo/bar", `/who/are/\*you`, `/\*you`}, {"/who/are/foo/bar", "/foo/bar", `/who/are/\*you`, `/\*you`},
 End of changes. 13 change blocks. 
7 lines changed or deleted 56 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)