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