diff --git a/pipeline/error_test.go b/pipeline/error_test.go new file mode 100644 index 0000000..7c69882 --- /dev/null +++ b/pipeline/error_test.go @@ -0,0 +1,32 @@ +package pipeline + +import ( + "testing" + + "github.com/pkg/errors" +) + +func TestErrorWithCause(t *testing.T) { + rootErr := errors.New("root cause error") + pipeErr := NewError(rootErr, "pipeline wrapper error") + wrapErr := errors.Wrap(pipeErr, "wrap with stack trace") + causeErr := errors.Cause(wrapErr) + if causeErr == nil { + t.Fatal("cause error should not be nil") + } + if causeErr != rootErr { + t.Fatal("cause error should be the same as root error") + } +} + +func TestErrorWithoutCause(t *testing.T) { + pipeErr := NewError(nil, "pipeline error without cause") + wrapErr := errors.Wrap(pipeErr, "wrap with stack trace") + causeErr := errors.Cause(wrapErr) + if causeErr == nil { + t.Fatal("cause error should not be nil") + } + if causeErr != pipeErr { + t.Fatal("cause error should be the same as pipeline error") + } +}