Created
October 18, 2018 14:12
-
-
Save slashdotdash/e146cac4f9cbf7236338ea8758a1910c to your computer and use it in GitHub Desktop.
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.DataCase do | |
use ExUnit.CaseTemplate | |
using do | |
quote do | |
import Commanded.Assertions.EventAssertions | |
end | |
end | |
setup do | |
{:ok, _} = Application.ensure_all_started(:my_app) | |
on_exit(fn -> | |
:ok = Application.stop(:my_app) | |
:ok = Application.stop(:commanded) | |
:ok = Application.stop(:eventstore) | |
MyApp.Storage.reset!() | |
end) | |
:ok | |
end | |
end |
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.Storage do | |
@doc """ | |
Clear the event store and read store databases | |
""" | |
def reset! do | |
reset_eventstore() | |
reset_readstore() | |
end | |
defp reset_eventstore do | |
config = EventStore.Config.parsed() |> EventStore.Config.default_postgrex_opts() | |
{:ok, conn} = Postgrex.start_link(config) | |
EventStore.Storage.Initializer.reset!(conn) | |
end | |
defp reset_readstore do | |
config = Application.get_env(:my_app, MyApp.Repo) | |
{:ok, conn} = Postgrex.start_link(config) | |
Postgrex.query!(conn, truncate_readstore_tables(), []) | |
end | |
defp truncate_readstore_tables do | |
""" | |
TRUNCATE TABLE | |
foo, | |
bar, | |
baz | |
RESTART IDENTITY | |
CASCADE; | |
""" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment