Invoke pg_embedded_setup_unpriv::bootstrap_for_tests() in integration suites
when both the prepared filesystem layout and the resulting settings are needed.
The helper performs the same orchestration as the CLI entry point but returns a
TestBootstrapSettings struct containing the final
postgresql_embedded::Settings and the environment variables required to
exercise the cluster.
use pg_embedded_setup_unpriv::{bootstrap_for_tests, TestBootstrapSettings};
use pg_embedded_setup_unpriv::error::BootstrapResult;
fn bootstrap() -> BootstrapResult<TestBootstrapSettings> {
let prepared = bootstrap_for_tests()?;
for (key, value) in prepared.environment.to_env() {
match value {
Some(value) => std::env::set_var(&key, value),
None => std::env::remove_var(&key),
}
}
Ok(prepared)
}
bootstrap_for_tests() ensures that
PGPASSFILE, HOME, XDG_CACHE_HOME, XDG_RUNTIME_DIR, and TZ are
populated with deterministic defaults. When a timezone database can be
discovered (currently on Unix-like hosts) the helper also sets TZDIR;
otherwise it leaves any caller-provided value untouched so platform-specific
defaults remain available. If the system timezone database is missing, the
helper returns an error advising the caller to install tzdata or set TZDIR
explicitly, making the dependency visible during test startup rather than when
PostgreSQL launches.