Improved tmpfile setup and teardown for tests

This commit is contained in:
Kieran Eglin 2024-02-15 10:07:58 -08:00
parent fecea9cc2f
commit 6ffa0d0477
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 15 additions and 5 deletions

View file

@ -34,6 +34,7 @@ defmodule PinchflatWeb.ConnCase do
setup tags do
Pinchflat.DataCase.setup_sandbox(tags)
Pinchflat.DataCase.setup_temp_filepaths()
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
end

View file

@ -32,6 +32,20 @@ defmodule Pinchflat.DataCase do
setup tags do
Pinchflat.DataCase.setup_sandbox(tags)
Pinchflat.DataCase.setup_temp_filepaths()
:ok
end
@doc """
Sets up the temp filepaths for the media and metadata directories.
"""
def setup_temp_filepaths do
File.rm_rf!(Application.get_env(:pinchflat, :media_directory))
File.rm_rf!(Application.get_env(:pinchflat, :metadata_directory))
File.mkdir_p!(Application.get_env(:pinchflat, :media_directory))
File.mkdir_p!(Application.get_env(:pinchflat, :metadata_directory))
:ok
end

View file

@ -4,8 +4,3 @@ Application.put_env(:pinchflat, :yt_dlp_runner, YtDlpRunnerMock)
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual)
Faker.start()
setup_all do
File.rm_rf(Application.get_env(:pinchflat, :media_directory))
File.rm_rf(Application.get_env(:pinchflat, :metadata_directory))
end