Skip to content

Commit

Permalink
Add test and comment.
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Martin <kubam@spacelift.io>
  • Loading branch information
cube2222 authored and wlynch committed Apr 7, 2023
1 parent e386e62 commit 535c380
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions transport.go
Expand Up @@ -64,6 +64,7 @@ func (e *HTTPError) Error() string {
return e.Message
}

// Unwrap implements the standard library's error wrapping. It unwraps to the root cause.
func (e *HTTPError) Unwrap() error {
return e.RootCause
}
Expand Down
13 changes: 13 additions & 0 deletions transport_test.go
Expand Up @@ -3,6 +3,7 @@ package ghinstallation
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -453,3 +454,15 @@ func TestExpiryAccessor(t *testing.T) {
})
}
}

func TestHTTPErrorUnwrap(t *testing.T) {
wrappedError := errors.New("wrapped error")

err := &HTTPError{
RootCause: wrappedError,
}

if !errors.Is(err, wrappedError) {
t.Errorf("HTTPError should be unwrapped to the root cause")
}
}

0 comments on commit 535c380

Please sign in to comment.