v2ray-core/app/router/router_test.go

49 lines
1.1 KiB
Go
Raw Normal View History

2016-10-12 16:11:13 +02:00
package router_test
import (
"testing"
"v2ray.com/core"
2016-08-20 20:55:45 +02:00
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/proxyman"
2017-01-06 15:32:36 +01:00
_ "v2ray.com/core/app/proxyman/outbound"
2016-10-12 16:11:13 +02:00
. "v2ray.com/core/app/router"
"v2ray.com/core/common"
2017-01-14 00:27:45 +01:00
"v2ray.com/core/common/net"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/session"
2018-10-21 10:27:13 +02:00
"v2ray.com/core/features/routing"
2017-10-24 16:15:35 +02:00
. "v2ray.com/ext/assert"
)
func TestSimpleRouter(t *testing.T) {
2017-10-24 16:15:35 +02:00
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},
},
},
2016-10-11 23:02:44 +02:00
},
}),
serial.ToTypedMessage(&dispatcher.Config{}),
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
2016-02-01 23:21:54 +01:00
},
}
v, err := core.New(config)
common.Must(err)
2018-10-21 10:27:13 +02:00
r := v.GetFeature(routing.RouterType()).(routing.Router)
2017-01-06 15:32:36 +01:00
ctx := withOutbound(&session.Outbound{Target: net.TCPDestination(net.DomainAddress("v2ray.com"), 80)})
tag, err := r.PickRoute(ctx)
2017-10-24 16:15:35 +02:00
assert(err, IsNil)
assert(tag, Equals, "test")
}