You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/app/router/router_test.go

49 lines
1.0 KiB

8 years ago
package router_test
import (
8 years ago
"context"
"testing"
"v2ray.com/core"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/proxyman"
_ "v2ray.com/core/app/proxyman/outbound"
8 years ago
. "v2ray.com/core/app/router"
"v2ray.com/core/common"
8 years ago
"v2ray.com/core/common/net"
"v2ray.com/core/common/serial"
8 years ago
"v2ray.com/core/proxy"
. "v2ray.com/ext/assert"
)
func TestSimpleRouter(t *testing.T) {
assert := With(t)
config := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&Config{
Rule: []*RoutingRule{
{
Tag: "test",
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
},
},
}),
serial.ToTypedMessage(&dispatcher.Config{}),
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
},
}
v, err := core.New(config)
common.Must(err)
r := v.Router()
ctx := proxy.ContextWithTarget(context.Background(), net.TCPDestination(net.DomainAddress("v2ray.com"), 80))
tag, err := r.PickRoute(ctx)
assert(err, IsNil)
assert(tag, Equals, "test")
}