mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
more test case for router
This commit is contained in:
parent
39134c1b82
commit
ed2779e333
@ -4,10 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"v2ray.com/core/common/session"
|
|
||||||
|
|
||||||
"v2ray.com/core/app/dispatcher"
|
"v2ray.com/core/app/dispatcher"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
|
"v2ray.com/core/common/session"
|
||||||
"v2ray.com/core/common/strmatcher"
|
"v2ray.com/core/common/strmatcher"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
)
|
)
|
||||||
|
@ -31,8 +31,6 @@ func withInbound(inbound *session.Inbound) context.Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRoutingRule(t *testing.T) {
|
func TestRoutingRule(t *testing.T) {
|
||||||
assert := With(t)
|
|
||||||
|
|
||||||
type ruleTest struct {
|
type ruleTest struct {
|
||||||
input context.Context
|
input context.Context
|
||||||
output bool
|
output bool
|
||||||
@ -126,6 +124,26 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
rule: &RoutingRule{
|
||||||
|
SourceCidr: []*CIDR{
|
||||||
|
{
|
||||||
|
Ip: []byte{192, 168, 0, 0},
|
||||||
|
Prefix: 16,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
test: []ruleTest{
|
||||||
|
{
|
||||||
|
input: withInbound(&session.Inbound{Source: net.TCPDestination(net.ParseAddress("192.168.0.1"), 80)}),
|
||||||
|
output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: withInbound(&session.Inbound{Source: net.TCPDestination(net.ParseAddress("10.0.0.1"), 80)}),
|
||||||
|
output: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
rule: &RoutingRule{
|
rule: &RoutingRule{
|
||||||
UserEmail: []string{
|
UserEmail: []string{
|
||||||
@ -158,14 +176,32 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
rule: &RoutingRule{
|
||||||
|
InboundTag: []string{"test", "test1"},
|
||||||
|
},
|
||||||
|
test: []ruleTest{
|
||||||
|
{
|
||||||
|
input: withInbound(&session.Inbound{Tag: "test"}),
|
||||||
|
output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: withInbound(&session.Inbound{Tag: "test2"}),
|
||||||
|
output: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range cases {
|
for _, test := range cases {
|
||||||
cond, err := test.rule.BuildCondition()
|
cond, err := test.rule.BuildCondition()
|
||||||
assert(err, IsNil)
|
common.Must(err)
|
||||||
|
|
||||||
for _, t := range test.test {
|
for _, subtest := range test.test {
|
||||||
assert(cond.Apply(t.input), Equals, t.output)
|
actual := cond.Apply(subtest.input)
|
||||||
|
if actual != subtest.output {
|
||||||
|
t.Error("test case failed: ", subtest.input, " expected ", subtest.output, " but got ", actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user