1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 19:45:24 +00:00
v2fly/app/router/router_test.go

49 lines
1.0 KiB
Go
Raw Normal View History

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