MCPcopy
hub / github.com/pkg/errors / TestCause

Function TestCause

errors_test.go:59–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57func (nilError) Error() string { return "nil error" }
58
59func TestCause(t *testing.T) {
60 x := New("error")
61 tests := []struct {
62 err error
63 want error
64 }{{
65 // nil error is nil
66 err: nil,
67 want: nil,
68 }, {
69 // explicit nil error is nil
70 err: (error)(nil),
71 want: nil,
72 }, {
73 // typed nil is nil
74 err: (*nilError)(nil),
75 want: (*nilError)(nil),
76 }, {
77 // uncaused error is unaffected
78 err: io.EOF,
79 want: io.EOF,
80 }, {
81 // caused error returns cause
82 err: Wrap(io.EOF, "ignored"),
83 want: io.EOF,
84 }, {
85 err: x, // return from errors.New
86 want: x,
87 }, {
88 WithMessage(nil, "whoops"),
89 nil,
90 }, {
91 WithMessage(io.EOF, "whoops"),
92 io.EOF,
93 }, {
94 WithStack(nil),
95 nil,
96 }, {
97 WithStack(io.EOF),
98 io.EOF,
99 }}
100
101 for i, tt := range tests {
102 got := Cause(tt.err)
103 if !reflect.DeepEqual(got, tt.want) {
104 t.Errorf("test %d: got %#v, want %#v", i+1, got, tt.want)
105 }
106 }
107}
108
109func TestWrapfNil(t *testing.T) {
110 got := Wrapf(nil, "no error")

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
WrapFunction · 0.85
WithMessageFunction · 0.85
WithStackFunction · 0.85
CauseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…