mirror of
https://github.com/gin-gonic/gin.git
synced 2025-08-06 07:40:39 +08:00
tests: make path assertions aware of vendoring
The path of a package can change in a situation where dependency vendoring is in use. This change modifies gin's unit tests to allow such paths.
This commit is contained in:
30
gin_test.go
30
gin_test.go
@ -214,32 +214,42 @@ func TestListOfRoutes(t *testing.T) {
|
||||
list := router.Routes()
|
||||
|
||||
assert.Len(t, list, 7)
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
assertRoutePresent(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/favicon.ico",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test1",
|
||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test1$",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
assertRoutePresent(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test1",
|
||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test1$",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
assertRoutePresent(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/users/",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test2",
|
||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test2$",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
assertRoutePresent(t, list, RouteInfo{
|
||||
Method: "GET",
|
||||
Path: "/users/:id",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test1",
|
||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test1$",
|
||||
})
|
||||
assert.Contains(t, list, RouteInfo{
|
||||
assertRoutePresent(t, list, RouteInfo{
|
||||
Method: "POST",
|
||||
Path: "/users/:id",
|
||||
Handler: "github.com/gin-gonic/gin.handler_test2",
|
||||
Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test2$",
|
||||
})
|
||||
}
|
||||
|
||||
func assertRoutePresent(t *testing.T, gotRoutes RoutesInfo, wantRoute RouteInfo) {
|
||||
for _, gotRoute := range gotRoutes {
|
||||
if gotRoute.Path == wantRoute.Path && gotRoute.Method == wantRoute.Method {
|
||||
assert.Regexp(t, wantRoute.Path, gotRoute.Path)
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Errorf("route not found: %v", wantRoute)
|
||||
}
|
||||
|
||||
func handler_test1(c *Context) {}
|
||||
func handler_test2(c *Context) {}
|
||||
|
Reference in New Issue
Block a user