router_test.go 729 B

123456789101112131415161718192021222324252627282930
  1. package rules
  2. import (
  3. "testing"
  4. "github.com/v2ray/v2ray-core/app/router/rules/config"
  5. testinconfig "github.com/v2ray/v2ray-core/app/router/rules/config/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 := &Router{
  13. rules: []config.Rule{
  14. &testinconfig.TestRule{
  15. TagValue: "test",
  16. Function: func(dest v2net.Destination) bool {
  17. return dest.IsTCP()
  18. },
  19. },
  20. },
  21. }
  22. tag, err := router.TakeDetour(v2net.NewTCPDestination(v2net.DomainAddress("v2ray.com", 80)))
  23. assert.Error(err).IsNil()
  24. assert.StringLiteral(tag).Equals("test")
  25. }