| 11 | ) |
| 12 | |
| 13 | func TestMultiError_Is(t *testing.T) { |
| 14 | customErr := fmt.Errorf("my error") |
| 15 | |
| 16 | testCases := map[string]struct { |
| 17 | sourceErrors []error |
| 18 | target error |
| 19 | is bool |
| 20 | }{ |
| 21 | "adding a context cancellation doesn't lose the information": { |
| 22 | sourceErrors: []error{context.Canceled}, |
| 23 | target: context.Canceled, |
| 24 | is: true, |
| 25 | }, |
| 26 | "adding multiple context cancellations doesn't lose the information": { |
| 27 | sourceErrors: []error{context.Canceled, context.Canceled}, |
| 28 | target: context.Canceled, |
| 29 | is: true, |
| 30 | }, |
| 31 | "adding wrapped context cancellations doesn't lose the information": { |
| 32 | sourceErrors: []error{errors.New("some error"), errors.Wrap(context.Canceled, "some message")}, |
| 33 | target: context.Canceled, |
| 34 | is: true, |
| 35 | }, |
| 36 | "adding a nil error doesn't lose the information": { |
| 37 | sourceErrors: []error{errors.New("some error"), errors.Wrap(context.Canceled, "some message"), nil}, |
| 38 | target: context.Canceled, |
| 39 | is: true, |
| 40 | }, |
| 41 | "errors with no context cancellation error are not a context canceled error": { |
| 42 | sourceErrors: []error{errors.New("first error"), errors.New("second error")}, |
| 43 | target: context.Canceled, |
| 44 | is: false, |
| 45 | }, |
| 46 | "no errors are not a context canceled error": { |
| 47 | sourceErrors: nil, |
| 48 | target: context.Canceled, |
| 49 | is: false, |
| 50 | }, |
| 51 | "no errors are a nil error": { |
| 52 | sourceErrors: nil, |
| 53 | target: nil, |
| 54 | is: true, |
| 55 | }, |
| 56 | "nested multi-error contains assert.AnError": { |
| 57 | sourceErrors: []error{ |
| 58 | assert.AnError, |
| 59 | New( |
| 60 | customErr, |
| 61 | fmt.Errorf("wrapped %w", context.Canceled), |
| 62 | ).Err(), |
| 63 | }, |
| 64 | target: assert.AnError, |
| 65 | is: true, |
| 66 | }, |
| 67 | "nested multi-error contains custom error": { |
| 68 | sourceErrors: []error{ |
| 69 | assert.AnError, |
| 70 | New( |