github.com/imannamdari/v2ray-core/v5@v5.0.5/app/dns/nameserver_doh_test.go (about) 1 package dns_test 2 3 import ( 4 "context" 5 "net/url" 6 "testing" 7 "time" 8 9 "github.com/google/go-cmp/cmp" 10 11 . "github.com/imannamdari/v2ray-core/v5/app/dns" 12 "github.com/imannamdari/v2ray-core/v5/common" 13 "github.com/imannamdari/v2ray-core/v5/common/net" 14 dns_feature "github.com/imannamdari/v2ray-core/v5/features/dns" 15 ) 16 17 func TestDoHLocalNameServer(t *testing.T) { 18 url, err := url.Parse("https+local://1.1.1.1/dns-query") 19 common.Must(err) 20 21 s := NewDoHLocalNameServer(url) 22 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) 23 ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns_feature.IPOption{ 24 IPv4Enable: true, 25 IPv6Enable: true, 26 }, false) 27 cancel() 28 common.Must(err) 29 if len(ips) == 0 { 30 t.Error("expect some ips, but got 0") 31 } 32 } 33 34 func TestDoHLocalNameServerWithCache(t *testing.T) { 35 url, err := url.Parse("https+local://1.1.1.1/dns-query") 36 common.Must(err) 37 38 s := NewDoHLocalNameServer(url) 39 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) 40 ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns_feature.IPOption{ 41 IPv4Enable: true, 42 IPv6Enable: true, 43 }, false) 44 cancel() 45 common.Must(err) 46 if len(ips) == 0 { 47 t.Error("expect some ips, but got 0") 48 } 49 50 ctx2, cancel := context.WithTimeout(context.Background(), time.Second*5) 51 ips2, err := s.QueryIP(ctx2, "google.com", net.IP(nil), dns_feature.IPOption{ 52 IPv4Enable: true, 53 IPv6Enable: true, 54 }, true) 55 cancel() 56 common.Must(err) 57 if r := cmp.Diff(ips2, ips); r != "" { 58 t.Fatal(r) 59 } 60 }