router_test.go 1.0 KB

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