Skip to content

Add tests for invalid, missing, and corrupted config file scenarios #151

Description

@sourcery-ai

There is currently a lack of tests covering error handling for invalid or corrupted config files in the codebase. To improve robustness and ensure proper error handling, we should add tests for the following scenarios:

  1. Missing config file: The application should either fall back to defaults or error gracefully when the config file is not present.
  2. Empty config file: The application should handle an empty config file gracefully, either by using defaults or by providing a clear error.
  3. Corrupted/invalid TOML config file: The application should return an error when the config file contains invalid TOML syntax.

Suggested implementation (in Rust):

  • Use tempfile to create temporary directories for config files.
  • Simulate each scenario by either omitting the config file, writing an empty file, or writing invalid TOML.
  • Assert that the config loading logic (load_and_merge()) returns the expected result (Ok for missing/empty, Err for invalid TOML).

Example test cases are provided below:

#[test]
fn test_missing_config_file() {
    // ... setup ...
    assert!(result.is_ok(), "Should handle missing config gracefully");
}

#[test]
fn test_empty_config_file() {
    // ... setup ...
    assert!(result.is_ok(), "Should handle empty config gracefully");
}

#[test]
fn test_invalid_toml_config_file() {
    // ... setup ...
    assert!(result.is_err(), "Should error on invalid TOML config");
}

Action items:

  • Add the above tests to the test suite for config loading.
  • Adjust test setup if your config logic uses different environment variables or file paths.
  • Ensure load_and_merge() returns a Result or update assertions to match its error handling.
  • Import necessary dependencies (tempfile, std::fs, std::env).

This will help verify the application's robustness against config file errors and improve overall reliability.


I created this issue for @leynos from #147 (comment).

Tips and commands

Getting Help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions