Skip to content

Commit 74caf47

Browse files
mateusz834gopherbot
authored andcommitted
net: use fake DNS dialer for /etc/hosts aliases tests
Change-Id: If9c41bd1e0497e76d901bfd2f749fbeb1ed3ac38 GitHub-Last-Rev: f5777d8 GitHub-Pull-Request: #61734 Reviewed-on: https://go-review.googlesource.com/c/go/+/515535 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Mateusz Poliwczak <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 7366720 commit 74caf47

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/net/dnsclient_unix_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"context"
1111
"errors"
1212
"fmt"
13-
"internal/testenv"
1413
"os"
1514
"path"
1615
"path/filepath"
@@ -2200,9 +2199,6 @@ var goLookupIPCNAMEOrderDNSFilesModeTests = []struct {
22002199
}
22012200

22022201
func TestGoLookupIPCNAMEOrderHostsAliasesDNSFilesMode(t *testing.T) {
2203-
if testenv.Builder() == "" {
2204-
t.Skip("Makes assumptions about local networks and (re)naming that aren't always true")
2205-
}
22062202
defer func(orig string) { testHookHostsPath = orig }(testHookHostsPath)
22072203
testHookHostsPath = "testdata/aliases"
22082204
mode := hostLookupDNSFiles
@@ -2213,9 +2209,29 @@ func TestGoLookupIPCNAMEOrderHostsAliasesDNSFilesMode(t *testing.T) {
22132209
}
22142210

22152211
func testGoLookupIPCNAMEOrderHostsAliases(t *testing.T, mode hostLookupOrder, lookup, lookupRes string) {
2212+
fake := fakeDNSServer{
2213+
rh: func(_, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) {
2214+
var answers []dnsmessage.Resource
2215+
2216+
if mode != hostLookupDNSFiles {
2217+
t.Fatal("received unexpected DNS query")
2218+
}
2219+
2220+
return dnsmessage.Message{
2221+
Header: dnsmessage.Header{
2222+
ID: q.Header.ID,
2223+
Response: true,
2224+
},
2225+
Questions: []dnsmessage.Question{q.Questions[0]},
2226+
Answers: answers,
2227+
}, nil
2228+
},
2229+
}
2230+
2231+
r := Resolver{PreferGo: true, Dial: fake.DialContext}
22162232
ins := []string{lookup, absDomainName(lookup), strings.ToLower(lookup), strings.ToUpper(lookup)}
22172233
for _, in := range ins {
2218-
_, res, err := goResolver.goLookupIPCNAMEOrder(context.Background(), "ip", in, mode, nil)
2234+
_, res, err := r.goLookupIPCNAMEOrder(context.Background(), "ip", in, mode, nil)
22192235
if err != nil {
22202236
t.Errorf("expected err == nil, but got error: %v", err)
22212237
}

0 commit comments

Comments
 (0)