File: error_test.go

package info (click to toggle)
golang-github-azure-azure-pipeline-go 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download
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")
	}
}