1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
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 TestErrorWithUnwrap(t *testing.T) {
rootErr := errors.New("root cause error")
pipeErr := NewError(rootErr, "pipeline wrapper error")
if !errors.Is(pipeErr, rootErr) {
t.Error("should be able to unrap rootErr")
}
}
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")
}
}
|