This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
packagerouter
import(
"testing"
ctxpkg"github.com/noahlann/nnet/pkg/context"
"github.com/stretchr/testify/assert"
)
funcTestRouterGroup(t*testing.T){
router:=NewRouter()
group:=router.Group()
assert.NotNil(t,group,"Expected group to be non-nil")
}
funcTestRouterGroupWithPrefix(t*testing.T){
router:=NewRouter()
group:=router.Group().(*routerGroup)
group.prefix="/api"
handler:=func(ctxctxpkg.Context)error{
returnnil
}
route:=group.RegisterString("/test",handler)
assert.NotNil(t,route,"Expected route to be non-nil")
// 测试前缀
assert.Equal(t,"/api",group.Prefix(),"Expected prefix to be /api")
}
funcTestRouterGroupWithMiddleware(t*testing.T){
router:=NewRouter()
middleware:=func(ctxctxpkg.Context)error{
returnnil
}
group:=router.Group()
group.Use(middleware)
handler:=func(ctxctxpkg.Context)error{
returnnil
}
route:=group.RegisterString("/test",handler)
assert.NotNil(t,route,"Expected route to be non-nil")
// 测试route的Handler方法(应该包含middleware)
routeHandler:=route.Handler()
assert.NotNil(t,routeHandler,"Expected handler to be non-nil")