Created
September 17, 2017 15:25
-
-
Save febeling/37d72e4a3f93738cb2a1b1f2602f9771 to your computer and use it in GitHub Desktop.
Storage case to base tests for eventstore on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.StorageCase do | |
use ExUnit.CaseTemplate | |
setup do | |
Application.stop(:myapp) | |
Application.stop(:commanded) | |
Application.stop(:eventstore) | |
reset_eventstore() | |
reset_readstore() | |
Application.ensure_all_started(:myapp) | |
:ok | |
end | |
defp reset_eventstore do | |
eventstore_config = | |
Application.get_env(:eventstore, EventStore.Storage) | |
|> Keyword.merge(pool: DBConnection.Poolboy) | |
{:ok, conn} = Postgrex.start_link(eventstore_config) | |
EventStore.Storage.Initializer.reset!(conn) | |
end | |
defp reset_readstore do | |
readstore_config = Application.get_env(:myapp, MyApp.Repo) | |
{:ok, conn} = Postgrex.start_link(readstore_config) | |
Postgrex.query!(conn, truncate_readstore_tables(), []) | |
end | |
defp truncate_readstore_tables do | |
""" | |
TRUNCATE TABLE | |
projection_versions, | |
-- ... additional read model tables | |
RESTART IDENTITY; | |
""" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment