]> Cypherpunks repositories - gostls13.git/commitdiff
net: use fake DNS dialer for /etc/hosts aliases tests
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Thu, 3 Aug 2023 09:34:44 +0000 (09:34 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 4 Aug 2023 02:44:33 +0000 (02:44 +0000)
Change-Id: If9c41bd1e0497e76d901bfd2f749fbeb1ed3ac38
GitHub-Last-Rev: f5777d8c20afb47b8cf093e43c7c25bbbb386e91
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>

src/net/dnsclient_unix_test.go

index 9ae68f9a992068ddf0978d50ae1d234f50dfbd04..dd0d32d3492597c32ddf88ca06e069da95b83e51 100644 (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)
                }