amuz.es/src/infra/goutils@v0.1.3/net/ipv4_resolver_test.go (about) 1 package net 2 3 import ( 4 "testing" 5 "net" 6 "github.com/benburkert/dns" 7 ) 8 9 func TestPreferIPV4Resolver(t *testing.T) { 10 var ( 11 cli = &dns.Client{Resolver: &PreferIPV4Resolver{}} 12 addrs []net.IP 13 err error 14 ) 15 addrs, err = net.LookupIP("www.v6.facebook.com") 16 if err == nil && len(addrs) != 0 && len(addrs[0]) == net.IPv6len { 17 err = nil 18 t.Log("checked AAAA dns reponse") 19 } else { 20 t.Fatal("unknown error : ", err) 21 } 22 23 net.DefaultResolver.PreferGo = true 24 net.DefaultResolver.Dial = cli.Dial 25 26 addrs, err = net.LookupIP("www.v6.facebook.com") 27 if len(addrs) != 0 { 28 t.Fatal("ipv6 address isn't empty") 29 } else if err == nil { 30 t.Fatal("no error in AAAA record") 31 } else if dnserr, ok := err.(*net.DNSError); !ok || dnserr.Err != "no such host" { 32 t.Fatal("unknown error : ", err) 33 } else { 34 err = nil 35 t.Log("AAAA dns request filtered") 36 } 37 }