Current section

Files

Jump to
split_client lib split_client testing testing.ex
Raw

lib/split_client/testing/testing.ex

defmodule SplitClient.Testing do
@moduledoc """
Functions to help with feature flag testing as well as
making the concurrently running tests isolated and
predictable
"""
alias SplitClient.Boundary.DataSourceStub
alias SplitClient.Sandbox
import ExUnit.Callbacks
@doc """
Add `setup :setup_split_client` to the top of your
test file. This will ensure that your Split.io
treatments are isolated to your test and not
inteferring with other tests running in parallel
"""
def setup_split_client(context) do
Sandbox.set_async_mode(context.async)
test_pid = self()
data_source_pid = start_supervised!(DataSourceStub)
# Add yaml defaults
DataSourceStub.create_splits(data_source_pid, [])
Sandbox.setup_test_treatments(self(), data_source_pid)
on_exit(fn ->
Sandbox.teardown_test_treatments(test_pid)
end)
{:ok, context}
end
# Convience for just having own import
defdelegate create_splits(splits), to: SplitClient.Sandbox
end