diff options
author | Shubham Sharma <shubham.sha12@gmail.com> | 2019-03-21 21:10:12 +0530 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-04-23 14:11:33 +0000 |
commit | fac3b5d05ecf31a2491949cc905312a34e272ae8 (patch) | |
tree | 4a82ef10460246d855e9ece69b40addfbfe561b2 /src/net/dnsclient_unix_test.go | |
parent | 7e08c7f43da876bc451b774808e323215a193abd (diff) | |
download | go-fac3b5d05ecf31a2491949cc905312a34e272ae8.tar.gz go-fac3b5d05ecf31a2491949cc905312a34e272ae8.zip |
net: add IsNotFound field to DNSError
This adds the ability to determine if a lookup error was
due to a non-existent hostname. Previously users needed
to do string matching on the DNSError.Err value.
Fixes #28635
Change-Id: If4bd3ad32cbc2db5614f2c6b72e0a9161d813efa
Reviewed-on: https://go-review.googlesource.com/c/go/+/168597
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/dnsclient_unix_test.go')
-rw-r--r-- | src/net/dnsclient_unix_test.go | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index f1ed58c837..1b67494e51 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -666,7 +666,7 @@ func TestErrorForOriginalNameWhenSearching(t *testing.T) { wantErr *DNSError }{ {true, &DNSError{Name: fqdn, Err: "server misbehaving", IsTemporary: true}}, - {false, &DNSError{Name: fqdn, Err: errNoSuchHost.Error()}}, + {false, &DNSError{Name: fqdn, Err: errNoSuchHost.Error(), IsNotFound: true}}, } for _, tt := range cases { r := Resolver{PreferGo: true, StrictErrors: tt.strictErrors, Dial: fake.DialContext} @@ -1138,9 +1138,10 @@ func TestStrictErrorsLookupIP(t *testing.T) { } makeNxDomain := func() error { return &DNSError{ - Err: errNoSuchHost.Error(), - Name: name, - Server: server, + Err: errNoSuchHost.Error(), + Name: name, + Server: server, + IsNotFound: true, } } @@ -1472,6 +1473,32 @@ func TestIssue8434(t *testing.T) { } } +func TestIssueNoSuchHostExists(t *testing.T) { + err := lookupWithFake(fakeDNSServer{ + rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { + return dnsmessage.Message{ + Header: dnsmessage.Header{ + ID: q.ID, + Response: true, + RCode: dnsmessage.RCodeNameError, + }, + Questions: q.Questions, + }, nil + }, + }, "golang.org.", dnsmessage.TypeALL) + if err == nil { + t.Fatal("expected an error") + } + if _, ok := err.(Error); !ok { + t.Fatalf("err = %#v; wanted something supporting net.Error", err) + } + if de, ok := err.(*DNSError); !ok { + t.Fatalf("err = %#v; wanted a *net.DNSError", err) + } else if !de.IsNotFound { + t.Fatalf("IsNotFound = false for err = %#v; want IsNotFound == true", err) + } +} + // TestNoSuchHost verifies that tryOneName works correctly when the domain does // not exist. // @@ -1541,6 +1568,9 @@ func TestNoSuchHost(t *testing.T) { if de.Err != errNoSuchHost.Error() { t.Fatalf("Err = %#v; wanted %q", de.Err, errNoSuchHost.Error()) } + if !de.IsNotFound { + t.Fatalf("IsNotFound = %v wanted true", de.IsNotFound) + } }) } } |