-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy patherror_test.go
More file actions
80 lines (61 loc) · 1.7 KB
/
error_test.go
File metadata and controls
80 lines (61 loc) · 1.7 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package oops
import (
"errors"
"io/fs"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrorsIs(t *testing.T) {
is := assert.New(t)
t.Parallel()
err := Errorf("Error: %w", fs.ErrExist)
is.ErrorIs(err, fs.ErrExist)
err = Wrap(fs.ErrExist)
is.ErrorIs(err, fs.ErrExist)
err = Wrap(fs.ErrExist)
is.ErrorIs(err, err) //nolint:testifylint
err = Wrapf(fs.ErrExist, "Error: %w", assert.AnError)
is.ErrorIs(err, fs.ErrExist)
err = Join(fs.ErrExist, assert.AnError)
is.ErrorIs(err, fs.ErrExist)
err = Join(assert.AnError, fs.ErrExist)
is.ErrorIs(err, fs.ErrExist)
err = Recover(func() {
panic(fs.ErrExist)
})
is.ErrorIs(err, fs.ErrExist)
err = Recoverf(func() {
panic(fs.ErrExist)
}, "Error: %w", assert.AnError)
is.ErrorIs(err, fs.ErrExist)
// Two independently created OopsErrors must not match each other.
// Previously, Is() returned true for any OopsError target regardless of identity.
err1 := Errorf("error 1")
err2 := Errorf("error 2")
is.False(errors.Is(err1, err2)) //nolint:testifylint
is.False(errors.Is(err2, err1)) //nolint:testifylint
}
func TestErrorsAs(t *testing.T) {
is := assert.New(t)
t.Parallel()
var anError error = &fs.PathError{Err: fs.ErrExist}
var target *fs.PathError
err := Errorf("Error: %w", anError)
is.ErrorAs(err, &target)
err = Wrap(anError)
is.ErrorAs(err, &target)
err = Wrapf(anError, "Error: %w", assert.AnError)
is.ErrorAs(err, &target)
err = Join(anError, assert.AnError)
is.ErrorAs(err, &target)
err = Join(assert.AnError, anError)
is.ErrorAs(err, &target)
err = Recover(func() {
panic(anError)
})
is.ErrorAs(err, &target)
err = Recoverf(func() {
panic(anError)
}, "Error: %w", assert.AnError)
is.ErrorAs(err, &target)
}