Files
Amit Kumar Ojha 6af5cc7d0b easyenv: add test coverage for typed env var getters (#1749)
## Summary

easyenv had no test coverage for boolean, num, string, or duration
getters, despite being used across every service and job in the
workspace. adds 34 tests covering the optional/required/or_default triad
for each type.tests use unique env var names per test instead of adding
`serial_test` dev-dep — `env::set_var` is process-global so cargo's
default parallel execution can race. cleanup via a `Drop` guard
(`EnvVarGuard`, in `tests_common.rs`) so a panicking test doesn't leak
state into its neighbors.

## follow-up

left `pathbuf.rs` for a separate PR — it depends on
`storyteller_root::get_substituted_path` which needs more setup than
belongs in this diff.

## behaviors these tests pin down but don't change

- boolean parsing only accepts `true` / `TRUE` / `false` / `FALSE` —
`"1"`, `"0"`, `"yes"`, `"no"` return `ParseError`
- duration parses whole seconds only, no `"5s"` style suffixes

worth flagging in case either is intentional and someone wants to loosen
these separately.

## verification

- `cargo test --package easyenv --test-threads=8` — 34/34 pass, no
flakes across 20 consecutive runs
- `cargo clippy --package easyenv -- -D warnings` — clean
2026-07-08 16:30:43 -04:00

69 lines
2.2 KiB
Rust

// Copyright (c) 2020 Brandon Thomas <bt@brand.io>
//! easyenv
//!
//! The interface between an app and its environment variables. This library makes it easy to:
//!
//! - read in strongly-typed environment variables.
//! - load default environment variables from one or more files in an order that supports
//! intentional overriding.
//!
//! Things that might want to move to another package :
//!
//! - configure env logging
//! - build conventions around system paths such that paths imported from environment variables
//! respect pathing conventions.
//!
//! This library does not:
//!
//! - handle app-specific conventions
//! - care about servers or deployed environments (eg. "staging" vs "production")
//!
#![deny(dead_code)]
#![deny(missing_docs)]
#![deny(unreachable_patterns)]
#![deny(unused_extern_crates)]
#![deny(unused_imports)]
#![deny(unused_qualifications)]
#![deny(unused_qualifications)]
// NB: These were exported from the root in previous versions.
// It's easy to just keep them exported here to maintain compatibility.
pub use error::EnvError;
pub use error::InitError;
pub use init::from_filename;
pub use init::init_all_with_default_logging;
pub use init::maybe_read_env_config_from_filename_and_paths;
pub use init::read_env_config_from_filename_and_paths;
pub use logging::DEFAULT_LOG_LEVEL;
pub use logging::ENV_RUST_LOG;
pub use logging::init_env_logger;
pub use types::boolean::get_env_bool_optional;
pub use types::boolean::get_env_bool_or_default;
pub use types::boolean::get_env_bool_required;
pub use types::duration::get_env_duration_seconds_optional;
pub use types::duration::get_env_duration_seconds_or_default;
pub use types::duration::get_env_duration_seconds_required;
pub use types::num::get_env_num;
pub use types::num::try_get_env_num_optional;
pub use types::pathbuf::get_env_pathbuf_optional;
pub use types::pathbuf::get_env_pathbuf_or_default;
pub use types::pathbuf::get_env_pathbuf_required;
pub use types::string::get_env_string_optional;
pub use types::string::get_env_string_or_default;
pub use types::string::get_env_string_required;
mod error;
mod init;
mod logging;
pub (crate) mod types;
#[cfg(test)]
mod tests_common;
/// Re-export of env_logger
pub mod env_logger {
pub use env_logger::Builder;
}