2020-12-25 06:13:50 -05:00
|
|
|
package dns_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-02-24 03:03:50 -05:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
. "github.com/v2fly/v2ray-core/v4/app/dns"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/net"
|
2021-02-22 21:17:20 -05:00
|
|
|
dns_feature "github.com/v2fly/v2ray-core/v4/features/dns"
|
2020-12-25 06:13:50 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestQUICNameServer(t *testing.T) {
|
|
|
|
url, err := url.Parse("quic://dns.adguard.com")
|
|
|
|
common.Must(err)
|
|
|
|
s, err := NewQUICNameServer(url)
|
|
|
|
common.Must(err)
|
2021-03-20 07:27:09 -04:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
2021-02-22 21:17:20 -05:00
|
|
|
ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns_feature.IPOption{
|
2020-12-25 06:13:50 -05:00
|
|
|
IPv4Enable: true,
|
|
|
|
IPv6Enable: true,
|
2021-02-24 03:03:50 -05:00
|
|
|
}, false)
|
|
|
|
cancel()
|
|
|
|
common.Must(err)
|
|
|
|
if len(ips) == 0 {
|
|
|
|
t.Error("expect some ips, but got 0")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestQUICNameServerWithCache(t *testing.T) {
|
|
|
|
url, err := url.Parse("quic://dns.adguard.com")
|
|
|
|
common.Must(err)
|
|
|
|
s, err := NewQUICNameServer(url)
|
|
|
|
common.Must(err)
|
2021-03-20 07:27:09 -04:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
2021-02-24 03:03:50 -05:00
|
|
|
ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns_feature.IPOption{
|
|
|
|
IPv4Enable: true,
|
|
|
|
IPv6Enable: true,
|
|
|
|
}, false)
|
2020-12-25 06:13:50 -05:00
|
|
|
cancel()
|
|
|
|
common.Must(err)
|
|
|
|
if len(ips) == 0 {
|
|
|
|
t.Error("expect some ips, but got 0")
|
|
|
|
}
|
2021-02-24 03:03:50 -05:00
|
|
|
|
2021-03-20 07:27:09 -04:00
|
|
|
ctx2, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
2021-02-24 03:03:50 -05:00
|
|
|
ips2, err := s.QueryIP(ctx2, "google.com", net.IP(nil), dns_feature.IPOption{
|
|
|
|
IPv4Enable: true,
|
|
|
|
IPv6Enable: true,
|
|
|
|
}, true)
|
|
|
|
cancel()
|
|
|
|
common.Must(err)
|
|
|
|
if r := cmp.Diff(ips2, ips); r != "" {
|
|
|
|
t.Fatal(r)
|
|
|
|
}
|
2020-12-25 06:13:50 -05:00
|
|
|
}
|