Bandera. Test
(bandera v0.1.0)
Copy Markdown
Test helpers for toggling Bandera flags with per-test, async-safe isolation.
Backed by Bandera.Store.ProcessScoped (NimbleOwnership). Setup:
# config/test.exs
config :bandera, store: Bandera.Store.ProcessScoped
# test/test_helper.exs
Bandera.Test.start()
# a test module
defmodule MyTest do
use ExUnit.Case, async: true
use Bandera.Test
@tag feature_flags: [my_flag: true]
test "feature on" do
assert Bandera.enabled?(:my_flag)
end
test "toggle in the body" do
enable_flag(:other)
assert Bandera.enabled?(:other)
end
endOverrides are scoped to the test process (and its $callers), so tests run
async: true without bleeding into each other, and enable_flag/disable_flag
never touch a database or fire notifications. Cleanup is automatic when the test
process exits (NimbleOwnership monitors owners); reset/0 clears overrides
explicitly within a test if needed.
The use Bandera.Test macro imports enable_flag/1,2 and disable_flag/1,2
for unqualified use. The remaining helpers — put_flag/2,3, clear/1, and
reset/0 — are called fully qualified, e.g. Bandera.Test.reset().
Consumers must add {:nimble_ownership, "~> 1.0", only: :test} to their deps.
Summary
Functions
Clear a single flag's overrides for the current process.
Disable a flag for the current process.
Disable a flag for a specific actor in the current process.
Enable a flag for the current process.
Enable a flag for a specific actor in the current process.
Set a flag's boolean value for the current process (and its $callers).
Set a flag's boolean value for a specific actor in the current process.
Clear ALL of the current process's flag overrides.
Start the NimbleOwnership server backing the process-scoped store.
Functions
@spec clear(atom()) :: :ok
Clear a single flag's overrides for the current process.
@spec disable_flag(atom()) :: :ok
Disable a flag for the current process.
Disable a flag for a specific actor in the current process.
@spec enable_flag(atom()) :: :ok
Enable a flag for the current process.
Enable a flag for a specific actor in the current process.
Set a flag's boolean value for the current process (and its $callers).
Set a flag's boolean value for a specific actor in the current process.
@spec reset() :: :ok
Clear ALL of the current process's flag overrides.
@spec start() :: :ok
Start the NimbleOwnership server backing the process-scoped store.
Idempotent — call once in test/test_helper.exs.