1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/app/router/router_test.go

49 lines
1.2 KiB
Go
Raw Normal View History

2016-10-12 10:11:13 -04:00
package router_test
import (
2017-01-13 07:41:40 -05:00
"context"
"testing"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
2017-01-06 09:32:36 -05:00
_ "v2ray.com/core/app/dispatcher/impl"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/app/dns"
2017-01-06 09:32:36 -05:00
_ "v2ray.com/core/app/dns/server"
2016-08-20 14:55:45 -04:00
"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"
2017-01-13 18:27:45 -05:00
"v2ray.com/core/common/net"
2016-10-19 06:01:11 -04:00
"v2ray.com/core/proxy"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
)
func TestSimpleRouter(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-10-11 17:02:44 -04:00
config := &Config{
Rule: []*RoutingRule{
2016-02-05 16:06:27 -05:00
{
2016-10-11 17:02:44 -04:00
Tag: "test",
2017-01-13 18:27:45 -05:00
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
2016-10-11 17:02:44 -04:00
},
2016-02-01 17:21:54 -05:00
},
},
}
2016-05-18 11:12:04 -04:00
space := app.NewSpace()
2017-01-13 07:41:40 -05:00
ctx := app.ContextWithSpace(context.Background(), space)
2017-10-24 10:15:35 -04:00
assert(app.AddApplicationToSpace(ctx, new(dns.Config)), IsNil)
assert(app.AddApplicationToSpace(ctx, new(dispatcher.Config)), IsNil)
assert(app.AddApplicationToSpace(ctx, new(proxyman.OutboundConfig)), IsNil)
assert(app.AddApplicationToSpace(ctx, config), IsNil)
assert(space.Initialize(), IsNil)
2017-01-06 09:32:36 -05:00
r := FromSpace(space)
2017-02-09 16:49:38 -05:00
ctx = proxy.ContextWithTarget(ctx, net.TCPDestination(net.DomainAddress("v2ray.com"), 80))
tag, err := r.TakeDetour(ctx)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(tag, Equals, "test")
}