| 11 | ) |
| 12 | |
| 13 | func 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 | |
| 44 | func TestSentinelWithMultipleWrappedErrors(t *testing.T) { |
| 45 | t.Parallel() |