1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:20:05 -07:00

net: use fake DNS dialer for /etc/hosts aliases tests

Change-Id: If9c41bd1e0497e76d901bfd2f749fbeb1ed3ac38
GitHub-Last-Rev: f5777d8c20
GitHub-Pull-Request: golang/go#61734
Reviewed-on: https://go-review.googlesource.com/c/go/+/515535
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2023-08-03 09:34:44 +00:00 committed by Gopher Robot
parent 73667209c1
commit 74caf475e3

View File

@ -10,7 +10,6 @@ import (
"context"
"errors"
"fmt"
"internal/testenv"
"os"
"path"
"path/filepath"
@ -2200,9 +2199,6 @@ var goLookupIPCNAMEOrderDNSFilesModeTests = []struct {
}
func TestGoLookupIPCNAMEOrderHostsAliasesDNSFilesMode(t *testing.T) {
if testenv.Builder() == "" {
t.Skip("Makes assumptions about local networks and (re)naming that aren't always true")
}
defer func(orig string) { testHookHostsPath = orig }(testHookHostsPath)
testHookHostsPath = "testdata/aliases"
mode := hostLookupDNSFiles
@ -2213,9 +2209,29 @@ func TestGoLookupIPCNAMEOrderHostsAliasesDNSFilesMode(t *testing.T) {
}
func testGoLookupIPCNAMEOrderHostsAliases(t *testing.T, mode hostLookupOrder, lookup, lookupRes string) {
fake := fakeDNSServer{
rh: func(_, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) {
var answers []dnsmessage.Resource
if mode != hostLookupDNSFiles {
t.Fatal("received unexpected DNS query")
}
return dnsmessage.Message{
Header: dnsmessage.Header{
ID: q.Header.ID,
Response: true,
},
Questions: []dnsmessage.Question{q.Questions[0]},
Answers: answers,
}, nil
},
}
r := Resolver{PreferGo: true, Dial: fake.DialContext}
ins := []string{lookup, absDomainName(lookup), strings.ToLower(lookup), strings.ToUpper(lookup)}
for _, in := range ins {
_, res, err := goResolver.goLookupIPCNAMEOrder(context.Background(), "ip", in, mode, nil)
_, res, err := r.goLookupIPCNAMEOrder(context.Background(), "ip", in, mode, nil)
if err != nil {
t.Errorf("expected err == nil, but got error: %v", err)
}