Skip to main content

test_production_config_with_env

Macro test_production_config_with_env 

Source
macro_rules! test_production_config_with_env {
    ($env_vars:expr, $test:expr) => { ... };
}
Expand description

All twelve #[macro_export] configuration test macros, re-exported from the subx-core crate.

#[macro_export] places a macro at its defining crate’s root, so pub use subx_core::config; above cannot reach them; they are listed individually. Legacy re-exports for consumers that have not yet migrated to subx_core:: paths, and will be removed once they have. Execute ProductionConfigService tests with specified environment variable mapping.

This macro creates a TestEnvironmentProvider, sets the specified environment variables, then uses that provider to create a ProductionConfigService for testing.

§Arguments

  • $env_vars - Environment variable mapping expression (HashMap<&str, &str>)
  • $test - Test closure that receives a ProductionConfigService reference

§Examples

use subx_core::{test_production_config_with_env, std::collections::HashMap};

let env_vars = [
    ("OPENAI_API_KEY", "sk-test-key"),
    ("OPENAI_BASE_URL", "https://test.api.com/v1")
].iter().cloned().collect::<HashMap<_, _>>();

test_production_config_with_env!(env_vars, |service| {
    let config = service.get_config().unwrap();
    assert_eq!(config.ai.api_key, Some("sk-test-key".to_string()));
    assert_eq!(config.ai.base_url, "https://test.api.com/v1");
});