-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr_test.go
More file actions
38 lines (31 loc) · 795 Bytes
/
err_test.go
File metadata and controls
38 lines (31 loc) · 795 Bytes
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
package utils
import (
"errors"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestErrorc(t *testing.T) {
t.Run("nil", func(t *testing.T) {
require.True(t, Errorc(nil) == nil)
})
t.Run("path", func(t *testing.T) {
err := Errorc(errors.New("oups"))
t.Logf("err.Error() = %s", err.Error())
require.Regexp(t, `utils/err_test.go:\d+ oups`, err.Error())
})
t.Run("is", func(t *testing.T) {
err := Errorc(os.ErrNotExist)
require.True(t, errors.Is(err, os.ErrNotExist))
})
t.Run("nice", func(t *testing.T) {
err := UserErrorfc(os.ErrNotExist, "Something bad happened %d", 5)
require.True(t, errors.Is(err, os.ErrNotExist))
})
}
func TestRootCause(t *testing.T) {
x := errors.New("x")
a := Errorc(x)
b := Errorc(a)
require.Equal(t, x, RootCause(b))
}