Skip to content

Commit

Permalink
bring back tests and functionality to check causable, and add more co…
Browse files Browse the repository at this point in the history
…verage for hasMessage
  • Loading branch information
atoulme committed Apr 28, 2023
1 parent a43f1f4 commit 2194d3f
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion errors/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,60 @@ package errors

import (
"errors"
"fmt"
"testing"

dropboxerrors "github.com/dropbox/godropbox/errors"
facebookerrors "github.com/facebookgo/stackerr"
. "github.com/smartystreets/goconvey/convey"
)

type causableErrorImpl struct {
root error
cause error
}

func (e causableErrorImpl) Error() string {
return fmt.Sprintf("%v\n\tcause:%v", e.root, e.cause)
}

func (e causableErrorImpl) Cause() error {
return e.cause
}

type messageErrorImpl struct {
root error
message string
}

func (e messageErrorImpl) Error() string {
return fmt.Sprintf("%v\n\tcause:%v", e.root, e.message)
}

func (e messageErrorImpl) Message() string {
return e.message
}
func TestMessageErrors(t *testing.T) {
Convey("When the original error implements hasMessage", t, func() {
err := messageErrorImpl{
root: errors.New("foo"),
message: "bar",
}
So(Message(err), ShouldEqual, "bar")
})
}

func TestCausableErrors(t *testing.T) {
Convey("When the original error implements causableError", t, func() {
cause := errors.New("cause")
err := causableErrorImpl{
root: errors.New("foo"),
cause: cause,
}
So(Cause(err), ShouldEqual, cause)
})
}

func TestGoDropbox(t *testing.T) {
Convey("When the original error is godropbox", t, func() {
root := dropboxerrors.New("dropbox root error")
Expand Down Expand Up @@ -40,7 +87,6 @@ func TestFacebookErrors(t *testing.T) {
fbWrap := facebookerrors.Wrap(root)
So(Tail(fbWrap), ShouldEqual, root)
myAnnotation := Annotate(fbWrap, "I have annotated fb error")
So(Cause(myAnnotation), ShouldEqual, root)

So(Tail(myAnnotation), ShouldEqual, root)
So(Cause(myAnnotation), ShouldEqual, root)
Expand Down

0 comments on commit 2194d3f

Please sign in to comment.