MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestGetCasErrorCode

Function TestGetCasErrorCode

pkg/ring/kv/metrics_test.go:17–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15func (e operationAbortedError) IsOperationAborted() bool { return true }
16
17func 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}

Callers

nothing calls this directly

Calls 3

getCasErrorCodeFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected