LemonCore. Testing. HermeticEnv
(lemon_core v0.1.0)
View Source
Shared helpers for keeping non-integration tests isolated from ambient machine state.
The default unit-test lane should not accidentally inherit a developer's real
provider or platform credentials. Tests that intentionally exercise live
integrations must opt in explicitly with LEMON_TEST_ALLOW_LIVE_CREDENTIALS=1
or by passing allow_live?: true.
Summary
Functions
Returns env vars considered live provider/platform credentials in unit tests.
Restores env vars captured with snapshot_env/1.
Scrubs live provider/platform credentials for normal unit-test lanes.
Captures current values for env vars.
Runs fun and restores the provided env vars afterward.
Functions
@spec credential_env_vars() :: [String.t()]
Returns env vars considered live provider/platform credentials in unit tests.
Restores env vars captured with snapshot_env/1.
@spec scrub_unit_credentials!(keyword()) :: :ok | {:skipped, :live_credentials_allowed}
Scrubs live provider/platform credentials for normal unit-test lanes.
Set LEMON_TEST_ALLOW_LIVE_CREDENTIALS=1 or pass allow_live?: true for an
explicit live/integration run that should inherit credentials.
Returns :ok when credentials are scrubbed, or
{:skipped, :live_credentials_allowed} when live credentials are explicitly
allowed.
Captures current values for env vars.
Runs fun and restores the provided env vars afterward.
This helper is intentionally small and synchronous. Use it from async: false
tests when mutating process-wide environment variables.