TestHandlerError tests the HandlerError structured error type
(t *testing.T)
| 1517 | |
| 1518 | // TestHandlerError tests the HandlerError structured error type |
| 1519 | func TestHandlerError(t *testing.T) { |
| 1520 | t.Run("HandlerErrorWithoutWrappedError", func(t *testing.T) { |
| 1521 | err := NewHandlerError("register", "TEST_NOTIFICATION", "handler already exists", nil) |
| 1522 | |
| 1523 | if err == nil { |
| 1524 | t.Error("NewHandlerError should not return nil") |
| 1525 | } |
| 1526 | |
| 1527 | expectedMsg := "handler register failed for 'TEST_NOTIFICATION': handler already exists" |
| 1528 | if err.Error() != expectedMsg { |
| 1529 | t.Errorf("HandlerError message should be '%s', got: %s", expectedMsg, err.Error()) |
| 1530 | } |
| 1531 | |
| 1532 | if err.Operation != "register" { |
| 1533 | t.Errorf("HandlerError Operation should be 'register', got: %s", err.Operation) |
| 1534 | } |
| 1535 | |
| 1536 | if err.PushNotificationName != "TEST_NOTIFICATION" { |
| 1537 | t.Errorf("HandlerError PushNotificationName should be 'TEST_NOTIFICATION', got: %s", err.PushNotificationName) |
| 1538 | } |
| 1539 | |
| 1540 | if err.Reason != "handler already exists" { |
| 1541 | t.Errorf("HandlerError Reason should be 'handler already exists', got: %s", err.Reason) |
| 1542 | } |
| 1543 | |
| 1544 | if err.Unwrap() != nil { |
| 1545 | t.Error("HandlerError Unwrap should return nil when no wrapped error") |
| 1546 | } |
| 1547 | }) |
| 1548 | |
| 1549 | t.Run("HandlerErrorWithWrappedError", func(t *testing.T) { |
| 1550 | wrappedErr := errors.New("underlying error") |
| 1551 | err := NewHandlerError("unregister", "PROTECTED_NOTIFICATION", "protected handler", wrappedErr) |
| 1552 | |
| 1553 | expectedMsg := "handler unregister failed for 'PROTECTED_NOTIFICATION': protected handler (underlying error)" |
| 1554 | if err.Error() != expectedMsg { |
| 1555 | t.Errorf("HandlerError message should be '%s', got: %s", expectedMsg, err.Error()) |
| 1556 | } |
| 1557 | |
| 1558 | if err.Unwrap() != wrappedErr { |
| 1559 | t.Error("HandlerError Unwrap should return the wrapped error") |
| 1560 | } |
| 1561 | }) |
| 1562 | } |
| 1563 | |
| 1564 | // TestProcessorError tests the ProcessorError structured error type |
| 1565 | func TestProcessorError(t *testing.T) { |
nothing calls this directly
no test coverage detected