You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

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.

package router
import (
"testing"
ctxpkg "github.com/noahlann/nnet/pkg/context"
"github.com/stretchr/testify/assert"
)
func TestRouterGroup(t *testing.T) {
router := NewRouter()
group := router.Group()
assert.NotNil(t, group, "Expected group to be non-nil")
}
func TestRouterGroupWithPrefix(t *testing.T) {
router := NewRouter()
group := router.Group().(*routerGroup)
group.prefix = "/api"
handler := func(ctx ctxpkg.Context) error {
return nil
}
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")
}
func TestRouterGroupWithMiddleware(t *testing.T) {
router := NewRouter()
middleware := func(ctx ctxpkg.Context) error {
return nil
}
group := router.Group()
group.Use(middleware)
handler := func(ctx ctxpkg.Context) error {
return nil
}
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")
}