From fde025ef7ce40b8cac95fd677a03e6e63ba1e220 Mon Sep 17 00:00:00 2001 From: Joni Collinge Date: Thu, 25 Oct 2018 09:31:06 +0100 Subject: [PATCH] added test to validate expected behavior --- pipeline/error_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pipeline/error_test.go 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") + } +}