hosts_test.go 729 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package dns_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/app/dns"
  5. . "v2ray.com/ext/assert"
  6. )
  7. func TestStaticHosts(t *testing.T) {
  8. assert := With(t)
  9. pb := []*Config_HostMapping{
  10. {
  11. Type: DomainMatchingType_Full,
  12. Domain: "v2ray.com",
  13. Ip: [][]byte{
  14. {1, 1, 1, 1},
  15. },
  16. },
  17. {
  18. Type: DomainMatchingType_Subdomain,
  19. Domain: "v2ray.cn",
  20. Ip: [][]byte{
  21. {2, 2, 2, 2},
  22. },
  23. },
  24. }
  25. hosts, err := NewStaticHosts(pb, nil)
  26. assert(err, IsNil)
  27. {
  28. ips := hosts.LookupIP("v2ray.com")
  29. assert(len(ips), Equals, 1)
  30. assert([]byte(ips[0]), Equals, []byte{1, 1, 1, 1})
  31. }
  32. {
  33. ips := hosts.LookupIP("www.v2ray.cn")
  34. assert(len(ips), Equals, 1)
  35. assert([]byte(ips[0]), Equals, []byte{2, 2, 2, 2})
  36. }
  37. }