router_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package rules_test
  2. import (
  3. "testing"
  4. "github.com/v2ray/v2ray-core/app"
  5. "github.com/v2ray/v2ray-core/app/dispatcher"
  6. dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
  7. "github.com/v2ray/v2ray-core/app/dns"
  8. "github.com/v2ray/v2ray-core/app/proxyman"
  9. "github.com/v2ray/v2ray-core/app/router"
  10. . "github.com/v2ray/v2ray-core/app/router/rules"
  11. v2net "github.com/v2ray/v2ray-core/common/net"
  12. v2testing "github.com/v2ray/v2ray-core/testing"
  13. "github.com/v2ray/v2ray-core/testing/assert"
  14. )
  15. func TestSimpleRouter(t *testing.T) {
  16. v2testing.Current(t)
  17. config := &RouterRuleConfig{
  18. Rules: []*Rule{
  19. {
  20. Tag: "test",
  21. Condition: NewNetworkMatcher(v2net.Network("tcp").AsList()),
  22. },
  23. },
  24. }
  25. space := app.NewSpace()
  26. space.BindApp(dns.APP_ID, dns.NewCacheServer(space, &dns.Config{}))
  27. space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
  28. space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
  29. r := NewRouter(config, space)
  30. space.BindApp(router.APP_ID, r)
  31. assert.Error(space.Initialize()).IsNil()
  32. tag, err := r.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80))
  33. assert.Error(err).IsNil()
  34. assert.StringLiteral(tag).Equals("test")
  35. }