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