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.

36 lines
1.1 KiB
Go

package matcher
import (
"testing"
"github.com/noahlann/nnet/internal/codec"
"github.com/noahlann/nnet/internal/request"
"github.com/noahlann/nnet/internal/response"
ctxpkg "github.com/noahlann/nnet/pkg/context"
routerpkg "github.com/noahlann/nnet/pkg/router"
"github.com/stretchr/testify/assert"
)
func TestStringMatcher(t *testing.T) {
// 创建测试Context
conn := &mockConnection{id: "test-conn"}
req := request.New([]byte("hello"), nil)
codecRegistry := codec.NewRegistry()
resp := response.New(conn, nil, codecRegistry, "json")
ctx := ctxpkg.New(nil, conn, req, resp)
// 创建字符串匹配器
matcher := routerpkg.NewStringMatcher("hello")
// 测试精确匹配
assert.True(t, matcher.Match(routerpkg.MatchInput{Raw: []byte("hello")}, ctx), "Expected match for 'hello'")
// 测试不匹配
assert.False(t, matcher.Match(routerpkg.MatchInput{Raw: []byte("world")}, ctx), "Expected no match for 'world'")
}
func TestStringMatcherPriority(t *testing.T) {
matcher := routerpkg.NewStringMatcher("test")
assert.Equal(t, 100, matcher.Priority(), "Expected priority to be 100")
}