1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 16:26:02 -04:00
v2fly/app/router/rules/router_test.go

41 lines
1.2 KiB
Go
Raw Normal View History

2015-12-07 16:47:47 -05:00
package rules_test
import (
"testing"
2016-05-18 11:12:04 -04:00
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dispatcher"
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
"github.com/v2ray/v2ray-core/app/dns"
"github.com/v2ray/v2ray-core/app/proxyman"
"github.com/v2ray/v2ray-core/app/router"
2015-12-07 16:47:47 -05:00
. "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestSimpleRouter(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-01 17:21:54 -05:00
config := &RouterRuleConfig{
Rules: []*Rule{
2016-02-05 16:06:27 -05:00
{
2016-02-01 17:21:54 -05:00
Tag: "test",
Condition: NewNetworkMatcher(v2net.Network("tcp").AsList()),
},
},
}
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)
space.BindApp(router.APP_ID, r)
assert.Error(space.Initialize()).IsNil()
2016-05-18 11:12:04 -04:00
tag, err := r.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80))
assert.Error(err).IsNil()
2016-05-24 15:55:46 -04:00
assert.String(tag).Equals("test")
}