MCPcopy Create free account
hub / github.com/IBM/sarama / TestSentinelWithSingleWrappedError

Function TestSentinelWithSingleWrappedError

errors_test.go:13–42  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestSentinelWithSingleWrappedError(t *testing.T) {
14 t.Parallel()
15 myNetError := &net.OpError{Op: "mock", Err: errors.New("op error")}
16 error := Wrap(ErrOutOfBrokers, myNetError)
17
18 expected := fmt.Sprintf("%s: %s", ErrOutOfBrokers, myNetError)
19 actual := error.Error()
20 if actual != expected {
21 t.Errorf("unexpected value '%s' vs '%v'", expected, actual)
22 }
23
24 if !errors.Is(error, ErrOutOfBrokers) {
25 t.Error("errors.Is unexpected result")
26 }
27
28 if !errors.Is(error, myNetError) {
29 t.Error("errors.Is unexpected result")
30 }
31
32 if opError, ok := errors.AsType[*net.OpError](error); !ok {
33 t.Error("errors.AsType unexpected result")
34 } else if opError != myNetError {
35 t.Error("errors.AsType wrong value")
36 }
37
38 unwrapped := errors.Unwrap(error)
39 if errors.Is(unwrapped, ErrOutOfBrokers) || !errors.Is(unwrapped, myNetError) {
40 t.Errorf("unexpected unwrapped value %v vs %vs", error, unwrapped)
41 }
42}
43
44func TestSentinelWithMultipleWrappedErrors(t *testing.T) {
45 t.Parallel()

Callers

nothing calls this directly

Calls 5

WrapFunction · 0.85
IsMethod · 0.80
ErrorMethod · 0.65
ErrorfMethod · 0.65
UnwrapMethod · 0.45

Tested by

no test coverage detected