I currently have an umbrella project containing a database service. I would like to seed this service automatically when I run the mix test
command but I can't.
I tried to put into apps/db_service/mix.ex
the following code
defp aliases do
[
"ecto.setup": ["ecto.create --quiet", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
"test": ["ecto.reset", "test"]
]
end
but I got an error if I run mix test
on the root directory : ** (Mix) The database for DatabaseService.Repo couldn't be dropped: ERROR 55006 (object_in_use)
(command is working into the service directory)
So I tried to put into root/mix.ex
defp aliases do
[
"test": ["ecto.drop", "ecto.create", "ecto.migrate", "test"]
]
end
and into apps/db_service/mix.ex
defp aliases do
[
"test": ["run priv/repo/seeds.exs", "test"]
]
end
but now, I get the following error : ** (Mix) No such file: priv/repo/seeds.exs
How can I do for seed my tests and have the mix test
command works in the root and in the service folder ?
This is a late answer but it is here:
defp aliases do
"test.seed": ["run #{Path.join(__DIR__, "priv/repo/seeds.exs")}"],
test: ["test.seed", "test"]
end
Taken from this response on Github.