router_test.go 693 B

123456789101112131415161718192021222324252627
  1. package rules_test
  2. import (
  3. "testing"
  4. . "github.com/v2ray/v2ray-core/app/router/rules"
  5. testinconfig "github.com/v2ray/v2ray-core/app/router/rules/testing"
  6. v2net "github.com/v2ray/v2ray-core/common/net"
  7. v2testing "github.com/v2ray/v2ray-core/testing"
  8. "github.com/v2ray/v2ray-core/testing/assert"
  9. )
  10. func TestSimpleRouter(t *testing.T) {
  11. v2testing.Current(t)
  12. router := NewRouter().AddRule(
  13. &testinconfig.TestRule{
  14. TagValue: "test",
  15. Function: func(dest v2net.Destination) bool {
  16. return dest.IsTCP()
  17. },
  18. })
  19. tag, err := router.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80))
  20. assert.Error(err).IsNil()
  21. assert.StringLiteral(tag).Equals("test")
  22. }