2015-12-07 16:47:47 -05:00
|
|
|
package rules_test
|
2015-11-30 10:14:38 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-12-07 16:47:47 -05:00
|
|
|
. "github.com/v2ray/v2ray-core/app/router/rules"
|
|
|
|
testinconfig "github.com/v2ray/v2ray-core/app/router/rules/testing"
|
2015-11-30 10:14:38 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-11-30 10:14:38 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleRouter(t *testing.T) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-11-30 10:14:38 -05:00
|
|
|
|
2015-12-07 16:47:47 -05:00
|
|
|
router := NewRouter().AddRule(
|
|
|
|
&testinconfig.TestRule{
|
|
|
|
TagValue: "test",
|
|
|
|
Function: func(dest v2net.Destination) bool {
|
|
|
|
return dest.IsTCP()
|
2015-11-30 10:14:38 -05:00
|
|
|
},
|
2015-12-07 16:47:47 -05:00
|
|
|
})
|
2015-11-30 10:14:38 -05:00
|
|
|
|
2015-12-16 17:53:38 -05:00
|
|
|
tag, err := router.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80))
|
2015-11-30 10:14:38 -05:00
|
|
|
assert.Error(err).IsNil()
|
2015-12-02 10:41:19 -05:00
|
|
|
assert.StringLiteral(tag).Equals("test")
|
2015-11-30 10:14:38 -05:00
|
|
|
}
|