nameserver_quic_test.go 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dns_test
  2. import (
  3. "context"
  4. "net/url"
  5. "testing"
  6. "time"
  7. "github.com/google/go-cmp/cmp"
  8. . "github.com/xtls/xray-core/app/dns"
  9. "github.com/xtls/xray-core/common"
  10. "github.com/xtls/xray-core/common/net"
  11. "github.com/xtls/xray-core/features/dns"
  12. )
  13. func TestQUICNameServer(t *testing.T) {
  14. url, err := url.Parse("quic://dns.adguard.com")
  15. common.Must(err)
  16. s, err := NewQUICNameServer(url)
  17. common.Must(err)
  18. ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
  19. ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns.IPOption{
  20. IPv4Enable: true,
  21. IPv6Enable: true,
  22. }, false)
  23. cancel()
  24. common.Must(err)
  25. if len(ips) == 0 {
  26. t.Error("expect some ips, but got 0")
  27. }
  28. ctx2, cancel := context.WithTimeout(context.Background(), time.Second*5)
  29. ips2, err := s.QueryIP(ctx2, "google.com", net.IP(nil), dns.IPOption{
  30. IPv4Enable: true,
  31. IPv6Enable: true,
  32. }, true)
  33. cancel()
  34. common.Must(err)
  35. if r := cmp.Diff(ips2, ips); r != "" {
  36. t.Fatal(r)
  37. }
  38. }