chinaip_json_test.go 779 B

123456789101112131415161718192021222324252627
  1. // +build json
  2. package rules_test
  3. import (
  4. "testing"
  5. . "github.com/v2ray/v2ray-core/app/router/rules"
  6. v2testing "github.com/v2ray/v2ray-core/testing"
  7. "github.com/v2ray/v2ray-core/testing/assert"
  8. )
  9. func TestChinaIPJson(t *testing.T) {
  10. v2testing.Current(t)
  11. rule := ParseRule([]byte(`{
  12. "type": "chinaip",
  13. "outboundTag": "x"
  14. }`))
  15. assert.StringLiteral(rule.Tag).Equals("x")
  16. assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn
  17. assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com
  18. assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com
  19. assert.Bool(rule.Apply(makeDestination("120.135.126.1"))).IsTrue()
  20. assert.Bool(rule.Apply(makeDestination("8.8.8.8"))).IsFalse()
  21. }