2016-10-12 10:11:13 -04:00
|
|
|
package router_test
|
2015-11-30 10:14:38 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/app"
|
|
|
|
"v2ray.com/core/app/dispatcher"
|
|
|
|
dispatchers "v2ray.com/core/app/dispatcher/impl"
|
|
|
|
"v2ray.com/core/app/dns"
|
|
|
|
"v2ray.com/core/app/proxyman"
|
2016-10-12 10:11:13 -04:00
|
|
|
. "v2ray.com/core/app/router"
|
2016-08-20 14:55:45 -04:00
|
|
|
v2net "v2ray.com/core/common/net"
|
2016-10-19 06:01:11 -04:00
|
|
|
"v2ray.com/core/proxy"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/testing/assert"
|
2015-11-30 10:14:38 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleRouter(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2015-11-30 10:14:38 -05:00
|
|
|
|
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",
|
|
|
|
NetworkList: &v2net.NetworkList{
|
|
|
|
Network: []v2net.Network{v2net.Network_TCP},
|
|
|
|
},
|
2016-02-01 17:21:54 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-05-18 11:12:04 -04:00
|
|
|
space := app.NewSpace()
|
|
|
|
space.BindApp(dns.APP_ID, dns.NewCacheServer(space, &dns.Config{}))
|
|
|
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
|
|
|
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
|
|
|
|
r := NewRouter(config, space)
|
2016-10-12 10:11:13 -04:00
|
|
|
space.BindApp(APP_ID, r)
|
2016-05-18 11:12:04 -04:00
|
|
|
assert.Error(space.Initialize()).IsNil()
|
2015-11-30 10:14:38 -05:00
|
|
|
|
2016-10-19 06:01:11 -04:00
|
|
|
tag, err := r.TakeDetour(&proxy.SessionInfo{Destination: v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)})
|
2015-11-30 10:14:38 -05:00
|
|
|
assert.Error(err).IsNil()
|
2016-05-24 15:55:46 -04:00
|
|
|
assert.String(tag).Equals("test")
|
2015-11-30 10:14:38 -05:00
|
|
|
}
|