dns_test.go 956 B

123456789101112131415161718192021222324252627282930313233
  1. package internal_test
  2. import (
  3. "net"
  4. "testing"
  5. . "github.com/v2ray/v2ray-core/app/dns/internal"
  6. apptesting "github.com/v2ray/v2ray-core/app/testing"
  7. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  8. "github.com/v2ray/v2ray-core/common/serial"
  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 := NewCache(&CacheConfig{
  15. TrustedTags: map[serial.StringLiteral]bool{
  16. serial.StringLiteral("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. }