fieldrule_test.go 705 B

1234567891011121314151617181920212223242526272829303132
  1. package json
  2. import (
  3. "testing"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
  6. "github.com/v2ray/v2ray-core/testing/unit"
  7. )
  8. func TestDomainMatching(t *testing.T) {
  9. assert := unit.Assert(t)
  10. rule := &FieldRule{
  11. Domain: "v2ray.com",
  12. }
  13. dest := v2net.NewTCPDestination(v2net.DomainAddress("www.v2ray.com", 80))
  14. assert.Bool(rule.Apply(dest)).IsTrue()
  15. }
  16. func TestPortMatching(t *testing.T) {
  17. assert := unit.Assert(t)
  18. rule := &FieldRule{
  19. Port: &v2nettesting.PortRange{
  20. FromValue: 0,
  21. ToValue: 100,
  22. },
  23. }
  24. dest := v2net.NewTCPDestination(v2net.DomainAddress("www.v2ray.com", 80))
  25. assert.Bool(rule.Apply(dest)).IsTrue()
  26. }