dns_test.go 932 B

123456789101112131415161718192021222324252627282930313233
  1. package dns_test
  2. import (
  3. "net"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/app/dns"
  6. dnstesting "github.com/v2ray/v2ray-core/app/dns/testing"
  7. apptesting "github.com/v2ray/v2ray-core/app/testing"
  8. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  9. v2testing "github.com/v2ray/v2ray-core/testing"
  10. )
  11. func TestDnsAdd(t *testing.T) {
  12. v2testing.Current(t)
  13. domain := "v2ray.com"
  14. cache := dns.NewCache(&dnstesting.CacheConfig{
  15. TrustedTags: map[string]bool{
  16. "testtag": true,
  17. },
  18. })
  19. ip := cache.Get(&apptesting.Context{}, domain)
  20. netassert.IP(ip).IsNil()
  21. cache.Add(&apptesting.Context{CallerTagValue: "notvalidtag"}, domain, []byte{1, 2, 3, 4})
  22. ip = cache.Get(&apptesting.Context{}, domain)
  23. netassert.IP(ip).IsNil()
  24. cache.Add(&apptesting.Context{CallerTagValue: "testtag"}, domain, []byte{1, 2, 3, 4})
  25. ip = cache.Get(&apptesting.Context{}, domain)
  26. netassert.IP(ip).Equals(net.IP([]byte{1, 2, 3, 4}))
  27. }