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.
nnet/internal/router/matcher/composite_test.go

33 lines
1016 B
Go

package matcher
import (
"testing"
ctxpkg "git.noahlan.cn/noahlan/nnet/v2/pkg/context"
routerpkg "git.noahlan.cn/noahlan/nnet/v2/pkg/router"
"github.com/stretchr/testify/assert"
)
type dummyContext struct {
ctxpkg.Context
}
func TestCompositeMatcher_AND(t *testing.T) {
m1 := routerpkg.NewStringMatcher("hello")
m2 := routerpkg.NewStringMatcher("hello*")
and := routerpkg.NewAndMatcher(m1, m2)
assert.True(t, and.Match(routerpkg.MatchInput{Raw: []byte("hello")}, &dummyContext{}))
assert.False(t, and.Match(routerpkg.MatchInput{Raw: []byte("hi")}, &dummyContext{}))
}
func TestCompositeMatcher_OR(t *testing.T) {
m1 := routerpkg.NewStringMatcher("hello")
m2 := routerpkg.NewStringMatcher("ping")
or := routerpkg.NewOrMatcher(m1, m2)
assert.True(t, or.Match(routerpkg.MatchInput{Raw: []byte("hello")}, &dummyContext{}))
assert.True(t, or.Match(routerpkg.MatchInput{Raw: []byte("ping")}, &dummyContext{}))
assert.False(t, or.Match(routerpkg.MatchInput{Raw: []byte("other")}, &dummyContext{}))
}