Skip to content

Commit

Permalink
Added timeout dns specific fallback condition test
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Jan 19, 2024
1 parent e61d1e4 commit bc1d45b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ably/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -146,3 +147,41 @@ func TestIssue_154(t *testing.T) {
assert.Equal(t, http.StatusMethodNotAllowed, et.StatusCode,
"expected %d got %d: %v", http.StatusMethodNotAllowed, et.StatusCode, err)
}

func Test_DNSOrTimeoutErr(t *testing.T) {
dnsErr := net.DNSError{
Err: "Can't resolve host",
Name: "Host unresolvable",
Server: "rest.ably.com",
IsTimeout: false,
IsTemporary: false,
IsNotFound: false,
}

WrappedDNSErr := fmt.Errorf("custom error occured %w", &dnsErr)
if !ably.IsTimeoutOrDnsErr(WrappedDNSErr) {
t.Fatalf("%v is a DNS error", WrappedDNSErr)
}

urlErr := url.Error{
URL: "rest.ably.io",
Err: errors.New("URL error occured"),
Op: "IO read OP",
}

if ably.IsTimeoutOrDnsErr(&urlErr) {
t.Fatalf("%v is not a DNS or timeout error", urlErr)
}

urlErr.Err = &dnsErr

if !ably.IsTimeoutOrDnsErr(WrappedDNSErr) {
t.Fatalf("%v is a DNS error", urlErr)
}

dnsErr.IsTimeout = true

if !ably.IsTimeoutOrDnsErr(WrappedDNSErr) {
t.Fatalf("%v is a timeout error", urlErr)
}
}
4 changes: 4 additions & 0 deletions ably/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func UnwrapStatusCode(err error) int {
return statusCode(err)
}

func IsTimeoutOrDnsErr(err error) bool {
return isTimeoutOrDnsErr(err)
}

func (a *Auth) Timestamp(ctx context.Context, query bool) (time.Time, error) {
return a.timestamp(ctx, query)
}
Expand Down

0 comments on commit bc1d45b

Please sign in to comment.