-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror_test.go
More file actions
53 lines (49 loc) · 1020 Bytes
/
Copy patherror_test.go
File metadata and controls
53 lines (49 loc) · 1020 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package s2
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrNotExistMessage(t *testing.T) {
err := fmt.Errorf("%w: test-object", ErrNotExist)
assert.Equal(t, "s2: object not exist: test-object", err.Error())
}
func TestErrNotExist_Is(t *testing.T) {
testCases := []struct {
caseName string
err error
want bool
}{
{
caseName: "wrapped",
err: fmt.Errorf("%w: test", ErrNotExist),
want: true,
},
{
caseName: "double wrapped",
err: fmt.Errorf("outer: %w", fmt.Errorf("%w: test", ErrNotExist)),
want: true,
},
{
caseName: "direct sentinel",
err: ErrNotExist,
want: true,
},
{
caseName: "other error",
err: errors.New("some other error"),
want: false,
},
{
caseName: "nil error",
err: nil,
want: false,
},
}
for _, tc := range testCases {
t.Run(tc.caseName, func(t *testing.T) {
assert.Equal(t, tc.want, errors.Is(tc.err, ErrNotExist))
})
}
}