chinaip_test.go 778 B

1234567891011121314151617181920212223242526
  1. package json
  2. import (
  3. "net"
  4. "testing"
  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 makeDestination(ip string) v2net.Destination {
  10. return v2net.TCPDestination(v2net.IPAddress(net.ParseIP(ip)), 80)
  11. }
  12. func TestChinaIP(t *testing.T) {
  13. v2testing.Current(t)
  14. rule := &ChinaIPRule{}
  15. assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn
  16. assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com
  17. assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com
  18. assert.Bool(rule.Apply(makeDestination("120.135.126.1"))).IsTrue()
  19. assert.Bool(rule.Apply(makeDestination("8.8.8.8"))).IsFalse()
  20. }