router_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/dns"
  9. _ "v2ray.com/core/app/dns/server"
  10. "v2ray.com/core/app/proxyman"
  11. _ "v2ray.com/core/app/proxyman/outbound"
  12. . "v2ray.com/core/app/router"
  13. "v2ray.com/core/common/net"
  14. "v2ray.com/core/proxy"
  15. "v2ray.com/core/testing/assert"
  16. )
  17. func TestSimpleRouter(t *testing.T) {
  18. assert := assert.On(t)
  19. config := &Config{
  20. Rule: []*RoutingRule{
  21. {
  22. Tag: "test",
  23. NetworkList: &net.NetworkList{
  24. Network: []net.Network{net.Network_TCP},
  25. },
  26. },
  27. },
  28. }
  29. space := app.NewSpace()
  30. ctx := app.ContextWithSpace(context.Background(), space)
  31. assert.Error(app.AddApplicationToSpace(ctx, new(dns.Config))).IsNil()
  32. assert.Error(app.AddApplicationToSpace(ctx, new(dispatcher.Config))).IsNil()
  33. assert.Error(app.AddApplicationToSpace(ctx, new(proxyman.OutboundConfig))).IsNil()
  34. assert.Error(app.AddApplicationToSpace(ctx, config)).IsNil()
  35. assert.Error(space.Initialize()).IsNil()
  36. r := FromSpace(space)
  37. ctx = proxy.ContextWithDestination(ctx, net.TCPDestination(net.DomainAddress("v2ray.com"), 80))
  38. tag, err := r.TakeDetour(ctx)
  39. assert.Error(err).IsNil()
  40. assert.String(tag).Equals("test")
  41. }