router_test.go 1022 B

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