added test to validate expected behavior

This commit is contained in:
Joni Collinge 2018-10-25 09:31:06 +01:00
Родитель 5f89ed6fc4
Коммит fde025ef7c
1 изменённых файлов: 32 добавлений и 0 удалений

32
pipeline/error_test.go Normal file
Просмотреть файл

@ -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")
}
}