mirror of
https://github.com/gin-gonic/gin.git
synced 2025-08-07 11:49:48 +08:00
test(route): add some test for routergroup (#4291)
Co-authored-by: chenhuiluo <luochenhui@butterfly.tech>
This commit is contained in:
parent
ae5be7fcb7
commit
a4ac275e07
@ -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")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user