-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stdlib_test.go
46 lines (36 loc) · 1.44 KB
/
stdlib_test.go
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
41
42
43
44
45
46
package errors_test
import (
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/tozd/go/errors"
)
func TestBase(t *testing.T) {
t.Parallel()
parent := errors.Base("Foobar")
assert.EqualError(t, parent, "Foobar")
assert.NoError(t, errors.Unwrap(parent)) //nolint:testifylint
assert.NotImplements(t, (*stackTracer)(nil), parent)
another := errors.Basef("Foobar")
assert.EqualError(t, another, "Foobar")
assert.NoError(t, errors.Unwrap(another)) //nolint:testifylint
assert.NotImplements(t, (*stackTracer)(nil), another)
child := errors.Basef("Foobar (%w)", parent)
assert.EqualError(t, child, "Foobar (Foobar)")
assert.Equal(t, parent, errors.Unwrap(child))
assert.NotImplements(t, (*stackTracer)(nil), child)
assert.ErrorIs(t, child, parent)
child2 := errors.BaseWrap(parent, "Foobar2")
assert.EqualError(t, child2, "Foobar2")
assert.Equal(t, parent, errors.Unwrap(child2))
assert.NotImplements(t, (*stackTracer)(nil), child2)
assert.ErrorIs(t, child2, parent)
child3 := errors.BaseWrapf(parent, "Foobar3 (%s)", parent)
assert.EqualError(t, child3, "Foobar3 (Foobar)")
assert.Equal(t, parent, errors.Unwrap(child3))
assert.NotImplements(t, (*stackTracer)(nil), child3)
assert.ErrorIs(t, child3, parent)
// We use w() to prevent static analysis.
child4 := errors.BaseWrapf(parent, "Foobar4 ("+w()+")", parent)
assert.EqualError(t, child4, "Foobar4 (%!w(*errors.errorString=&{Foobar}))")
assert.ErrorIs(t, child4, parent)
}