Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoch786 committed Dec 5, 2024
1 parent 68c18c1 commit 5c384f7
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"net/http"
"net/http/httptest"
"os"
"reflect"
"runtime"
"strings"
"testing"

"github.com/gofiber/utils/v2"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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, " "))
}
}

//////////////////////////////////////////////
Expand Down

0 comments on commit 5c384f7

Please sign in to comment.