Skip to content

Feat/producer unit tests#12

Merged
kris927b merged 4 commits into
mainfrom
feat/producer-unit-tests
Jun 19, 2025
Merged

Feat/producer unit tests#12
kris927b merged 4 commits into
mainfrom
feat/producer-unit-tests

Conversation

@kris927b

Copy link
Copy Markdown
Owner

No description provided.

google-labs-jules Bot and others added 4 commits June 19, 2025 06:59
This commit introduces a comprehensive suite of unit tests for the `producer.rs` binary.

Key changes include:

1.  **Refactoring for Testability:**
    *   The `Args` struct was moved from `src/bin/producer.rs` to `src/config.rs` to allow its use in both the binary and test modules.
    *   The core logic functions `publish_tasks` and `aggregate_results` were moved from `src/bin/producer.rs` to a new library module `src/producer_logic.rs`.
    *   Introduced `TaskPublisherChannel` and `ResultConsumerChannel` traits in `src/producer_logic.rs` to abstract `lapin::Channel` operations. This allows mocking these operations during testing.
    *   `publish_tasks` and `aggregate_results` were made generic over these new traits.

2.  **Mocking Infrastructure:**
    *   Added `mock_lapin` module within `src/tests/producer_tests.rs`.
    *   `MockChannel` now implements `lapin::Channel` (base trait), `TaskPublisherChannel`, and `ResultConsumerChannel` to simulate RabbitMQ interactions.
    *   `MockConsumer` struct created to simulate `lapin::Consumer` behavior for `aggregate_results` tests.

3.  **Unit Tests Added:**
    *   **Argument Parsing (`args_tests`):** Tests for `clap` argument parsing, including default values and error conditions.
    *   **`publish_tasks` (`publish_tasks_tests`):**
        *   Successful publishing of tasks.
        *   Handling of Parquet reading errors.
        *   Handling of RabbitMQ queue declaration and publish errors.
        *   Behavior with empty input files.
    *   **`aggregate_results` (`aggregate_results_tests`):**
        *   Successful aggregation of results (both `Success` and `Filtered` outcomes).
        *   Verification of output Parquet file contents.
        *   Handling of RabbitMQ queue declaration and consume errors.
        *   Handling of message deserialization errors and stream errors during consumption.
        *   Behavior with no expected results (`published_count = 0`).

4.  **Test Utilities:**
    *   Helper functions in `src/tests/producer_tests.rs` for creating temporary Parquet files with `TextDocument` and `ProcessingOutcome` data.
    *   Helper function to create mock `lapin::message::Delivery` objects.

This work significantly improves the robustness and maintainability of the producer binary by ensuring its core components are well-tested.
…ub modules depending on config usage (e.g. pipeline)
@kris927b kris927b merged commit 289b36b into main Jun 19, 2025
1 check passed
@kris927b kris927b deleted the feat/producer-unit-tests branch June 19, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant