add some test for routergroup

This commit is contained in:
chenhuiluo 2025-07-09 19:20:15 +08:00 committed by chenhuiluo
parent cf4775283e
commit 62bfdcdfd6

View File

@ -11,6 +11,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var MaxHandlers = 32
func init() { func init() {
SetMode(TestMode) SetMode(TestMode)
} }
@ -193,3 +195,25 @@ func testRoutesInterface(t *testing.T, r IRoutes) {
assert.Equal(t, r, r.Static("/static", ".")) assert.Equal(t, r, r.Static("/static", "."))
assert.Equal(t, r, r.StaticFS("/static2", Dir(".", false))) assert.Equal(t, r, r.StaticFS("/static2", Dir(".", false)))
} }
func TestRouterGroupCombineHandlersTooManyHandlers(t *testing.T) {
group := &RouterGroup{
Handlers: make(HandlersChain, MaxHandlers), // Assume group already has MaxHandlers middleware
}
tooManyHandlers := make(HandlersChain, MaxHandlers) // Add MaxHandlers more, total 2 * MaxHandlers
// This should trigger panic
assert.Panics(t, func() {
group.combineHandlers(tooManyHandlers)
}, "should panic due to too many handlers")
}
func TestRouterGroupCombineHandlersEmptySliceNotNil(t *testing.T) {
group := &RouterGroup{
Handlers: HandlersChain{},
}
result := group.combineHandlers(HandlersChain{})
assert.NotNil(t, result, "result should not be nil even with empty handlers")
assert.Empty(t, result, "empty handlers should return empty chain")
}