-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
55 lines (42 loc) · 1.35 KB
/
errors_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
47
48
49
50
51
52
53
54
55
package errors_test
import (
stdErrors "errors"
"fmt"
"testing"
errors "github.com/TheDSCPL/minimal-errors"
"github.com/TheDSCPL/minimal-errors/internal"
"github.com/stretchr/testify/assert"
)
func TestStdlibAliases(t *testing.T) {
internal.AssertEqualFn(t, stdErrors.New, errors.New)
internal.AssertEqualFn(t, stdErrors.As, errors.As)
internal.AssertEqualFn(t, stdErrors.Is, errors.Is)
internal.AssertEqualFn(t, stdErrors.Unwrap, errors.Unwrap)
internal.AssertEqualFn(t, fmt.Errorf, errors.Errorf)
}
func TestWrap(t *testing.T) {
baseErr := stdErrors.New("base")
err := errors.Wrap(baseErr, "wrap")
assert.Equal(t, "wrap: base", err.Error())
assert.Equal(t, baseErr, errors.Unwrap(err))
err = errors.Wrap(baseErr, "")
assert.Equal(t, "base", err.Error())
assert.Equal(t, baseErr, errors.Unwrap(err))
err = errors.Wrap(nil, "foo")
assert.Nil(t, err)
}
func TestRedefine(t *testing.T) {
oldErr := stdErrors.New("old")
baseErr := stdErrors.New("base")
err := errors.Redefine(baseErr, oldErr)
assert.Equal(t, "base: old", err.Error())
assert.Equal(t, baseErr, errors.Unwrap(err))
err = errors.Redefine(baseErr, nil)
assert.Equal(t, "base", err.Error())
assert.Equal(t, baseErr, err)
err = errors.Redefine(nil, oldErr)
assert.Equal(t, "old", err.Error())
assert.Nil(t, errors.Unwrap(err))
err = errors.Redefine(nil, nil)
assert.Nil(t, err)
}