From 5c384f752a0ee236f78f9ad7446d0a94ab04be30 Mon Sep 17 00:00:00 2001 From: Cory Koch Date: Thu, 5 Dec 2024 02:07:55 -0500 Subject: [PATCH] Fix test --- router_test.go | 61 +++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/router_test.go b/router_test.go index 15a75a1f04..327b0cf531 100644 --- a/router_test.go +++ b/router_test.go @@ -12,6 +12,9 @@ import ( "net/http" "net/http/httptest" "os" + "reflect" + "runtime" + "strings" "testing" "github.com/gofiber/utils/v2" @@ -448,24 +451,7 @@ func Test_App_Remove_Route(t *testing.T) { require.Equal(t, uint32(2), app.handlersCount) require.Equal(t, uint32(2), app.routesCount) - // TODO not sure if this is needed - // from app.printRoutesMessage() - // var routes []RouteMessage - // for _, routeStack := range app.stack { - // for _, route := range routeStack { - // var newRoute RouteMessage - // newRoute.name = route.Name - // newRoute.method = route.Method - // newRoute.path = route.Path - // for _, handler := range route.Handlers { - // newRoute.handlers += runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name() + " " - // } - // routes = append(routes, newRoute) - // } - // } - // for _, route := range routes { - // require.Equal(t, 1, strings.Count(route.handlers, " ")) - // } + verifyRouteHandlerCounts(app, t) } func Test_App_Remove_Route_With_Middleware(t *testing.T) { @@ -524,24 +510,27 @@ func Test_App_Remove_Route_With_Middleware(t *testing.T) { require.Equal(t, uint32(3), app.handlersCount) require.Equal(t, uint32(2), app.routesCount) - // TODO not sure if this test is needed still looking into it - // from app.printRoutesMessage() - // var routes []RouteMessage - // for _, routeStack := range app.stack { - // for _, route := range routeStack { - // var newRoute RouteMessage - // newRoute.name = route.Name - // newRoute.method = route.Method - // newRoute.path = route.Path - // for _, handler := range route.Handlers { - // newRoute.handlers += runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name() + " " - // } - // routes = append(routes, newRoute) - // } - // } - // for _, route := range routes { - // require.Equal(t, 1, strings.Count(route.handlers, " ")) - // } + verifyRouteHandlerCounts(app, t) +} + +// this is taken from app.printRoutesMessage() +func verifyRouteHandlerCounts(app *App, t testing.TB) { + var routes []RouteMessage + for _, routeStack := range app.stack { + for _, route := range routeStack { + var newRoute RouteMessage + newRoute.name = route.Name + newRoute.method = route.Method + newRoute.path = route.Path + for _, handler := range route.Handlers { + newRoute.handlers += runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name() + " " + } + routes = append(routes, newRoute) + } + } + for _, route := range routes { + require.Equal(t, 1, strings.Count(route.handlers, " ")) + } } //////////////////////////////////////////////