-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdns_test.go
52 lines (43 loc) · 1.29 KB
/
dns_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log"
"testing"
)
var (
defaultTestDoHProvider = "https://doh.360.cn/dns-query"
)
func TestLookupStaticHost(t *testing.T) {
log.Println(goLookupIPFiles("youtube.com"))
log.Println(goLookupIPFiles("localhost"))
log.Println(goLookupIPFiles("host.docker.internal"))
log.Println((&dnsOverHostsFile{}).lookup("host.docker.internal"))
}
func TestCachedDNSLookUP(t *testing.T) {
dns := newCachedDNS(&dnsOverHostsFile{}, &dnsOverHTTPS{provider: defaultTestDoHProvider}, &dnsOverUDP{})
log.Println(dns.lookup("youtube.com"))
log.Println(dns.lookup("localhost"))
log.Println(dns.lookup("www.google.com"))
log.Println(dns.lookup("www.baidu.com"))
}
func TestDNSOverHTTPSLookUP(t *testing.T) {
dns := &dnsOverHTTPS{provider: defaultTestDoHProvider}
log.Println(dns.lookup("www.baidu.com"))
}
func BenchmarkCachedDNSLookUP(b *testing.B) {
var dns dnsResovler
dns = newCachedDNS(
&dnsOverHostsFile{},
&dnsOverHTTPS{provider: defaultTestDoHProvider},
&dnsOverUDP{},
)
for i := 0; i < b.N; i++ {
dns.lookup("www.baidu.com")
}
}
func BenchmarkUDPDNSLookUP(b *testing.B) {
var dns dnsResovler
dns = &dnsOverUDP{}
for i := 0; i < b.N; i++ {
dns.lookup("www.baidu.com")
}
}