router_test.go 651 B

1234567891011121314151617181920212223242526272829
  1. package rules_test
  2. import (
  3. "testing"
  4. . "github.com/v2ray/v2ray-core/app/router/rules"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. v2testing "github.com/v2ray/v2ray-core/testing"
  7. "github.com/v2ray/v2ray-core/testing/assert"
  8. )
  9. func TestSimpleRouter(t *testing.T) {
  10. v2testing.Current(t)
  11. config := &RouterRuleConfig{
  12. Rules: []*Rule{
  13. {
  14. Tag: "test",
  15. Condition: NewNetworkMatcher(v2net.Network("tcp").AsList()),
  16. },
  17. },
  18. }
  19. router := NewRouter(config, nil)
  20. tag, err := router.TakeDetour(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80))
  21. assert.Error(err).IsNil()
  22. assert.StringLiteral(tag).Equals("test")
  23. }