Skip to content

Commit feebb40

Browse files
bdns: replace direct type assertions with errors.As (letsencrypt#5122)
errors.As checks for a specific error in a wrapped error chain (see https://golang.org/pkg/errors/#As) as opposed to asserting that an error is of a specific type Part of letsencrypt#5010
1 parent 7ca1221 commit feebb40

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bdns/dns_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ func TestDNSLookupHost(t *testing.T) {
368368
t.Logf("%s - IP: %s, Err: %s", hostname, ip, err)
369369
test.AssertError(t, err, "Should be an error")
370370
expectedErr := DNSError{dns.TypeA, hostname, nil, dns.RcodeRefused}
371-
if err, ok := err.(*DNSError); !ok || *err != expectedErr {
371+
var dnserr *DNSError
372+
if !(errors.As(err, &dnserr) && *dnserr == expectedErr) {
372373
t.Errorf("Looking up %s, got %#v, expected %#v", hostname, err, expectedErr)
373374
}
374375
}
@@ -379,13 +380,14 @@ func TestDNSNXDOMAIN(t *testing.T) {
379380
hostname := "nxdomain.letsencrypt.org"
380381
_, err := obj.LookupHost(context.Background(), hostname)
381382
expected := DNSError{dns.TypeA, hostname, nil, dns.RcodeNameError}
382-
if err, ok := err.(*DNSError); !ok || *err != expected {
383+
var dnserr *DNSError
384+
if !(errors.As(err, &dnserr) && *dnserr == expected) {
383385
t.Errorf("Looking up %s, got %#v, expected %#v", hostname, err, expected)
384386
}
385387

386388
_, err = obj.LookupTXT(context.Background(), hostname)
387389
expected.recordType = dns.TypeTXT
388-
if err, ok := err.(*DNSError); !ok || *err != expected {
390+
if !(errors.As(err, &dnserr) && *dnserr == expected) {
389391
t.Errorf("Looking up %s, got %#v, expected %#v", hostname, err, expected)
390392
}
391393
}

0 commit comments

Comments
 (0)