router_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package router_test
  2. import (
  3. "context"
  4. "testing"
  5. "v2ray.com/core/app"
  6. "v2ray.com/core/app/dispatcher"
  7. _ "v2ray.com/core/app/dispatcher/impl"
  8. "v2ray.com/core/app/proxyman"
  9. _ "v2ray.com/core/app/proxyman/outbound"
  10. . "v2ray.com/core/app/router"
  11. "v2ray.com/core/common/net"
  12. "v2ray.com/core/proxy"
  13. . "v2ray.com/ext/assert"
  14. )
  15. func TestSimpleRouter(t *testing.T) {
  16. assert := With(t)
  17. config := &Config{
  18. Rule: []*RoutingRule{
  19. {
  20. Tag: "test",
  21. NetworkList: &net.NetworkList{
  22. Network: []net.Network{net.Network_TCP},
  23. },
  24. },
  25. },
  26. }
  27. space := app.NewSpace()
  28. ctx := app.ContextWithSpace(context.Background(), space)
  29. assert(app.AddApplicationToSpace(ctx, new(dispatcher.Config)), IsNil)
  30. assert(app.AddApplicationToSpace(ctx, new(proxyman.OutboundConfig)), IsNil)
  31. assert(app.AddApplicationToSpace(ctx, config), IsNil)
  32. assert(space.Initialize(), IsNil)
  33. r := FromSpace(space)
  34. ctx = proxy.ContextWithTarget(ctx, net.TCPDestination(net.DomainAddress("v2ray.com"), 80))
  35. tag, err := r.TakeDetour(ctx)
  36. assert(err, IsNil)
  37. assert(tag, Equals, "test")
  38. }