-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
81 lines (74 loc) · 1.96 KB
/
error_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
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
81
package clap
import (
"errors"
"fmt"
"github.com/hashicorp/go-multierror"
"github.com/stretchr/testify/assert"
"testing"
)
func TestError_Is(t *testing.T) {
var testCases = map[string]struct {
Err error
Target Error
Match bool
}{
"NotError": {
Err: fmt.Errorf("some error"),
Target: ErrMissing,
Match: false,
},
"CausedScanErr": {
Err: ErrScanning(fmt.Errorf("some err: %w", ErrMissing), "mock", "token"),
Target: ErrMissing,
Match: true,
},
"DidNotCauseScanErr": {
Err: ErrScanning(fmt.Errorf("some err: %w", ErrUnidentified), "mock", "token"),
Target: ErrMissing,
},
"ErrMissingMatch": {
Err: fmt.Errorf("should be missing: %w", ErrMissing),
Target: ErrMissing,
Match: true,
},
"ErrMissingDoesNotMatchMatch": {
Err: fmt.Errorf("should be missing: %w", ErrDuplicate),
Target: ErrMissing,
},
"MultiErrDetectErrMissing": {
Err: &multierror.Error{Errors: []error{ErrMissing, ErrDuplicate}},
Target: ErrMissing,
Match: true,
},
"MultiErrDetectErrDuplicate": {
Err: &multierror.Error{Errors: []error{ErrMissing, ErrDuplicate}},
Target: ErrDuplicate,
Match: true,
},
"MultiErrShouldNotDetectErr": {
Err: &multierror.Error{Errors: []error{ErrMissing, ErrDuplicate}},
Target: ErrInvalid,
},
"WMultiErrDetectErrMissing": {
Err: &multierror.Error{Errors: []error{fmt.Errorf("some err: %w", ErrMissing), ErrDuplicate}},
Target: ErrMissing,
Match: true,
},
"WMultiErrDetectErrDuplicate": {
Err: &multierror.Error{Errors: []error{ErrMissing, fmt.Errorf("some err: %w", ErrDuplicate)}},
Target: ErrDuplicate,
Match: true,
},
"WMultiErrShouldNotDetectErr": {
Err: &multierror.Error{Errors: []error{ErrMissing, ErrDuplicate}},
Target: ErrInvalid,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
a := assert.New(t)
match := errors.Is(tc.Err, tc.Target)
a.Equal(tc.Match, match)
})
}
}