chinasites_json_test.go 890 B

123456789101112131415161718192021222324252627282930313233
  1. // +build json
  2. package router_test
  3. import (
  4. "testing"
  5. . "v2ray.com/core/app/router"
  6. v2net "v2ray.com/core/common/net"
  7. "v2ray.com/core/testing/assert"
  8. )
  9. func makeDomainDestination(domain string) v2net.Destination {
  10. return v2net.TCPDestination(v2net.DomainAddress(domain), 80)
  11. }
  12. func TestChinaSitesJson(t *testing.T) {
  13. assert := assert.On(t)
  14. rule := ParseRule([]byte(`{
  15. "type": "chinasites",
  16. "outboundTag": "y"
  17. }`))
  18. assert.String(rule.Tag).Equals("y")
  19. cond, err := rule.BuildCondition()
  20. assert.Error(err).IsNil()
  21. assert.Bool(cond.Apply(makeDomainDestination("v.qq.com"))).IsTrue()
  22. assert.Bool(cond.Apply(makeDomainDestination("www.163.com"))).IsTrue()
  23. assert.Bool(cond.Apply(makeDomainDestination("ngacn.cc"))).IsTrue()
  24. assert.Bool(cond.Apply(makeDomainDestination("12306.cn"))).IsTrue()
  25. assert.Bool(cond.Apply(makeDomainDestination("v2ray.com"))).IsFalse()
  26. }