diff --git a/mxresolv/mxresolv.go b/mxresolv/mxresolv.go index c2c5418b..a604695b 100644 --- a/mxresolv/mxresolv.go +++ b/mxresolv/mxresolv.go @@ -27,6 +27,8 @@ var ( // It is modified only in tests to make them deterministic. shuffle = true + + DefaultResolver = net.DefaultResolver ) func init() { @@ -48,7 +50,7 @@ func Lookup(ctx context.Context, hostname string) ([]string, bool, error) { if err != nil { return nil, false, errors.Wrap(err, "invalid hostname") } - mxRecords, err := net.DefaultResolver.LookupMX(ctx, asciiHostname) + mxRecords, err := DefaultResolver.LookupMX(ctx, asciiHostname) if err != nil { var timeouter interface{ Timeout() bool } if errors.As(err, &timeouter) && timeouter.Timeout() { @@ -56,7 +58,7 @@ func Lookup(ctx context.Context, hostname string) ([]string, bool, error) { } var netDNSError *net.DNSError if errors.As(err, &netDNSError) && netDNSError.Err == "no such host" { - if _, err := net.DefaultResolver.LookupIPAddr(ctx, asciiHostname); err != nil { + if _, err := DefaultResolver.LookupIPAddr(ctx, asciiHostname); err != nil { return cacheAndReturn(hostname, nil, false, errors.WithStack(err)) } return cacheAndReturn(hostname, []string{asciiHostname}, true, nil)