v2ray-core/app/router/router_test.go

46 lines
1.1 KiB
Go
Raw Normal View History

2016-10-12 16:11:13 +02:00
package router_test
import (
"testing"
2016-08-20 20:55:45 +02:00
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
2017-01-06 15:32:36 +01:00
_ "v2ray.com/core/app/dispatcher/impl"
2016-08-20 20:55:45 +02:00
"v2ray.com/core/app/dns"
2017-01-06 15:32:36 +01:00
_ "v2ray.com/core/app/dns/server"
2016-08-20 20:55:45 +02:00
"v2ray.com/core/app/proxyman"
2017-01-06 15:32:36 +01:00
_ "v2ray.com/core/app/proxyman/outbound"
2016-10-12 16:11:13 +02:00
. "v2ray.com/core/app/router"
2016-08-20 20:55:45 +02:00
v2net "v2ray.com/core/common/net"
2016-10-19 12:01:11 +02:00
"v2ray.com/core/proxy"
2016-08-20 20:55:45 +02:00
"v2ray.com/core/testing/assert"
)
func TestSimpleRouter(t *testing.T) {
2016-05-24 21:55:46 +02:00
assert := assert.On(t)
2016-10-11 23:02:44 +02:00
config := &Config{
Rule: []*RoutingRule{
2016-02-05 22:06:27 +01:00
{
2016-10-11 23:02:44 +02:00
Tag: "test",
NetworkList: &v2net.NetworkList{
Network: []v2net.Network{v2net.Network_TCP},
},
2016-02-01 23:21:54 +01:00
},
},
}
2016-05-18 08:12:04 -07:00
space := app.NewSpace()
2017-01-06 15:32:36 +01:00
assert.Error(space.AddApp(new(dns.Config))).IsNil()
assert.Error(space.AddApp(new(dispatcher.Config))).IsNil()
assert.Error(space.AddApp(new(proxyman.OutboundConfig))).IsNil()
assert.Error(space.AddApp(config)).IsNil()
2016-05-18 08:12:04 -07:00
assert.Error(space.Initialize()).IsNil()
2017-01-06 15:32:36 +01:00
r := FromSpace(space)
2016-10-19 12:01:11 +02:00
tag, err := r.TakeDetour(&proxy.SessionInfo{Destination: v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)})
assert.Error(err).IsNil()
2016-05-24 21:55:46 +02:00
assert.String(tag).Equals("test")
}