test: add unit tests for environment variable bindings#747
Conversation
Adds coverage for all FACT_* env-var bindings in FactCli: - env_vars: each env var populates the correct FactConfig field - env_vars_override_yaml: env vars take precedence over YAML config - env_vars_invalid_values: invalid values produce ValueValidation errors Introduces EnvVar and EnvVarGuard helper types that together acquire ENV_MUTEX, set the variable, and guarantee removal on drop — even if the test panics. std::env::set_var is not safe in multi-threaded programs; the mutex serialises all env-var mutations within the suite as the least invasive available mitigation. Closes #730 Assisted-by: Claude Sonnet 4.6
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds concurrency-safe test infrastructure and three tests that verify FACT_* environment variables populate FactConfig fields, override YAML configuration when applied, and produce clap parse/validation errors for invalid values. ChangesEnvironment Variable Test Coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
/retest fact-on-push |
Extends env_vars_override_yaml test to cover all configuration variables that can be set via environment variables: - FACT_CERTS - FACT_ENDPOINT_ADDRESS - FACT_ENDPOINT_EXPOSE_METRICS - FACT_ENDPOINT_HEALTH_CHECK - FACT_SKIP_PRE_FLIGHT - FACT_HOTRELOAD Extends env_vars_invalid_values test to cover boolean flags and improves error message assertions by checking the full first line of the error output instead of just the error source. All 13 environment variables from FactCli are now comprehensively tested across env_vars, env_vars_override_yaml, and env_vars_invalid_values test functions. Assisted-by: Claude Code (claude-sonnet-4-5@20250929)
Description
Adds coverage for all FACT_* env-var bindings in FactCli:
Introduces EnvVar and EnvVarGuard helper types that together acquire ENV_MUTEX, set the variable, and guarantee removal on drop — even if the test panics. std::env::set_var is not safe in multi-threaded programs; the mutex serialises all env-var mutations within the suite as the least invasive available mitigation.
Closes #730
Assisted-by: Claude Sonnet 4.6
Checklist
Automated testing
If any of these don't apply, please comment below.
Testing Performed
Run the tests manually.
Summary by CodeRabbit