1package pipeline
2
3import (
4	"testing"
5
6	"github.com/pkg/errors"
7)
8
9func TestErrorWithCause(t *testing.T) {
10	rootErr := errors.New("root cause error")
11	pipeErr := NewError(rootErr, "pipeline wrapper error")
12	wrapErr := errors.Wrap(pipeErr, "wrap with stack trace")
13	causeErr := errors.Cause(wrapErr)
14	if causeErr == nil {
15		t.Fatal("cause error should not be nil")
16	}
17	if causeErr != rootErr {
18		t.Fatal("cause error should be the same as root error")
19	}
20}
21
22func TestErrorWithoutCause(t *testing.T) {
23	pipeErr := NewError(nil, "pipeline error without cause")
24	wrapErr := errors.Wrap(pipeErr, "wrap with stack trace")
25	causeErr := errors.Cause(wrapErr)
26	if causeErr == nil {
27		t.Fatal("cause error should not be nil")
28	}
29	if causeErr != pipeErr {
30		t.Fatal("cause error should be the same as pipeline error")
31	}
32}
33