chinaip_test.go 841 B

123456789101112131415161718192021222324252627
  1. package rules_test
  2. import (
  3. "net"
  4. "testing"
  5. . "github.com/v2ray/v2ray-core/app/router/rules"
  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 makeDestination(ip string) v2net.Destination {
  11. return v2net.TCPDestination(v2net.IPAddress(net.ParseIP(ip)), 80)
  12. }
  13. func TestChinaIP(t *testing.T) {
  14. v2testing.Current(t)
  15. rule := NewChinaIPRule("tag")
  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. }