1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-29 13:35:20 -05:00

Routing: Implement Route interface as the routing result of Router

This commit is contained in:
Vigilans
2020-09-18 17:30:59 +08:00
parent df2d296ffc
commit 4d5a4f4cb6
6 changed files with 122 additions and 65 deletions

View File

@@ -45,9 +45,9 @@ func TestSimpleRouter(t *testing.T) {
}))
ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: net.TCPDestination(net.DomainAddress("v2ray.com"), 80)})
tag, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
route, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
common.Must(err)
if tag != "test" {
if tag := route.GetOutboundTag(); tag != "test" {
t.Error("expect tag 'test', bug actually ", tag)
}
}
@@ -86,9 +86,9 @@ func TestSimpleBalancer(t *testing.T) {
}))
ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: net.TCPDestination(net.DomainAddress("v2ray.com"), 80)})
tag, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
route, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
common.Must(err)
if tag != "test" {
if tag := route.GetOutboundTag(); tag != "test" {
t.Error("expect tag 'test', bug actually ", tag)
}
}
@@ -121,9 +121,9 @@ func TestIPOnDemand(t *testing.T) {
common.Must(r.Init(config, mockDns, nil))
ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: net.TCPDestination(net.DomainAddress("v2ray.com"), 80)})
tag, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
route, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
common.Must(err)
if tag != "test" {
if tag := route.GetOutboundTag(); tag != "test" {
t.Error("expect tag 'test', bug actually ", tag)
}
}
@@ -156,9 +156,9 @@ func TestIPIfNonMatchDomain(t *testing.T) {
common.Must(r.Init(config, mockDns, nil))
ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: net.TCPDestination(net.DomainAddress("v2ray.com"), 80)})
tag, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
route, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
common.Must(err)
if tag != "test" {
if tag := route.GetOutboundTag(); tag != "test" {
t.Error("expect tag 'test', bug actually ", tag)
}
}
@@ -190,9 +190,9 @@ func TestIPIfNonMatchIP(t *testing.T) {
common.Must(r.Init(config, mockDns, nil))
ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: net.TCPDestination(net.LocalHostIP, 80)})
tag, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
route, err := r.PickRoute(routing_session.AsRoutingContext(ctx))
common.Must(err)
if tag != "test" {
if tag := route.GetOutboundTag(); tag != "test" {
t.Error("expect tag 'test', bug actually ", tag)
}
}