From cf56b89898ad6781e1e7452a3a2e70b27f8e94e3 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 12 Dec 2015 20:47:29 +0100 Subject: [PATCH] more router test cases --- app/router/router_test.go | 31 +++++++++++++++++++++++++++ app/router/rules/json/chinaip_test.go | 1 + 2 files changed, 32 insertions(+) create mode 100644 app/router/router_test.go diff --git a/app/router/router_test.go b/app/router/router_test.go new file mode 100644 index 000000000..12a0e8967 --- /dev/null +++ b/app/router/router_test.go @@ -0,0 +1,31 @@ +package router_test + +import ( + "net" + "path/filepath" + "testing" + + . "github.com/v2ray/v2ray-core/app/router" + _ "github.com/v2ray/v2ray-core/app/router/rules/json" + v2net "github.com/v2ray/v2ray-core/common/net" + "github.com/v2ray/v2ray-core/shell/point/json" + v2testing "github.com/v2ray/v2ray-core/testing" + "github.com/v2ray/v2ray-core/testing/assert" +) + +func TestRouter(t *testing.T) { + v2testing.Current(t) + + baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config" + + pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json")) + assert.Error(err).IsNil() + + router, err := CreateRouter(pointConfig.RouterConfig().Strategy(), pointConfig.RouterConfig().Settings()) + assert.Error(err).IsNil() + + dest := v2net.NewTCPDestination(v2net.IPAddress(net.ParseIP("120.135.126.1"), 80)) + tag, err := router.TakeDetour(dest) + assert.Error(err).IsNil() + assert.StringLiteral(tag).Equals("direct") +} diff --git a/app/router/rules/json/chinaip_test.go b/app/router/rules/json/chinaip_test.go index 8d611e956..d90e34216 100644 --- a/app/router/rules/json/chinaip_test.go +++ b/app/router/rules/json/chinaip_test.go @@ -20,6 +20,7 @@ func TestChinaIP(t *testing.T) { assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com + assert.Bool(rule.Apply(makeDestination("120.135.126.1"))).IsTrue() assert.Bool(rule.Apply(makeDestination("8.8.8.8"))).IsFalse() }