(t *testing.T)
| 15 | func (e operationAbortedError) IsOperationAborted() bool { return true } |
| 16 | |
| 17 | func TestGetCasErrorCode(t *testing.T) { |
| 18 | abortedErr := operationAbortedError{} |
| 19 | |
| 20 | tests := map[string]struct { |
| 21 | err error |
| 22 | expected string |
| 23 | }{ |
| 24 | "nil error": { |
| 25 | err: nil, |
| 26 | expected: "200", |
| 27 | }, |
| 28 | "operation aborted error (direct)": { |
| 29 | err: abortedErr, |
| 30 | expected: "200", |
| 31 | }, |
| 32 | "operation aborted error (single-wrapped by memberlist)": { |
| 33 | err: fmt.Errorf("fn returned error: %w", abortedErr), |
| 34 | expected: "200", |
| 35 | }, |
| 36 | "operation aborted error (double-wrapped by memberlist)": { |
| 37 | err: fmt.Errorf("failed to CAS-update key X: %w", |
| 38 | fmt.Errorf("fn returned error: %w", abortedErr)), |
| 39 | expected: "200", |
| 40 | }, |
| 41 | "generic error": { |
| 42 | err: fmt.Errorf("some real error"), |
| 43 | expected: "500", |
| 44 | }, |
| 45 | } |
| 46 | |
| 47 | for name, tc := range tests { |
| 48 | t.Run(name, func(t *testing.T) { |
| 49 | assert.Equal(t, tc.expected, getCasErrorCode(tc.err)) |
| 50 | }) |
| 51 | } |
| 52 | } |
nothing calls this directly
no test coverage detected