diff --git a/test/pinchflat/downloader/backends/yt_dlp/channel_test.exs b/test/pinchflat/downloader/backends/yt_dlp/channel_test.exs index 2380577..86b6c27 100644 --- a/test/pinchflat/downloader/backends/yt_dlp/channel_test.exs +++ b/test/pinchflat/downloader/backends/yt_dlp/channel_test.exs @@ -11,7 +11,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.ChannelTest do describe "get_channel_info/1" do test "it returns a %ChannelDetails{} with data on success" do - expect(CommandRunnerMock, :run, fn _url, _opts -> + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"} end) @@ -20,7 +20,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.ChannelTest do end test "it passes the expected args to the backend runner" do - expect(CommandRunnerMock, :run, fn @channel_url, opts -> + expect(YtDlpRunnerMock, :run, fn @channel_url, opts -> assert opts == [{:print, "%(.{channel,channel_id})j"}, {:playlist_end, 1}] {:ok, "{}"} @@ -30,13 +30,13 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.ChannelTest do end test "it returns an error if the runner returns an error" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:error, "Big issue", 1} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:error, "Big issue", 1} end) assert {:error, "Big issue", 1} = Channel.get_channel_info(@channel_url) end test "it returns an error if the output is not JSON" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:ok, "Not JSON"} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "Not JSON"} end) assert {:error, %Jason.DecodeError{}} = Channel.get_channel_info(@channel_url) end diff --git a/test/pinchflat/downloader/backends/yt_dlp/video_collection_test.exs b/test/pinchflat/downloader/backends/yt_dlp/video_collection_test.exs index 3ae667a..a67131e 100644 --- a/test/pinchflat/downloader/backends/yt_dlp/video_collection_test.exs +++ b/test/pinchflat/downloader/backends/yt_dlp/video_collection_test.exs @@ -14,13 +14,13 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoCollectionTest do describe "get_video_ids/2" do test "returns a list of video ids with no blank elements" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:ok, "id1\nid2\n\nid3\n"} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "id1\nid2\n\nid3\n"} end) assert {:ok, ["id1", "id2", "id3"]} = VideoCollectionUser.get_video_ids(@channel_url) end test "it passes the expected default args" do - expect(CommandRunnerMock, :run, fn _url, opts -> + expect(YtDlpRunnerMock, :run, fn _url, opts -> assert opts == [:simulate, :skip_download, {:print, :id}] {:ok, ""} @@ -30,7 +30,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoCollectionTest do end test "it passes the expected custom args" do - expect(CommandRunnerMock, :run, fn _url, opts -> + expect(YtDlpRunnerMock, :run, fn _url, opts -> assert opts == [:custom_arg, :simulate, :skip_download, {:print, :id}] {:ok, ""} @@ -40,7 +40,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoCollectionTest do end test "returns the error straight through when the command fails" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:error, "Big issue", 1} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:error, "Big issue", 1} end) assert {:error, "Big issue", 1} = VideoCollectionUser.get_video_ids(@channel_url) end diff --git a/test/pinchflat/downloader/backends/yt_dlp/video_test.exs b/test/pinchflat/downloader/backends/yt_dlp/video_test.exs index a71bfff..667e3f8 100644 --- a/test/pinchflat/downloader/backends/yt_dlp/video_test.exs +++ b/test/pinchflat/downloader/backends/yt_dlp/video_test.exs @@ -10,7 +10,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoTest do describe "download/2" do test "it calls the backend runner with the expected arguments" do - expect(CommandRunnerMock, :run, fn @video_url, opts -> + expect(YtDlpRunnerMock, :run, fn @video_url, opts -> assert opts == [:no_simulate, {:print, "%()j"}] {:ok, "{}"} @@ -20,7 +20,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoTest do end test "it passes along additional options" do - expect(CommandRunnerMock, :run, fn _url, opts -> + expect(YtDlpRunnerMock, :run, fn _url, opts -> assert opts == [:no_simulate, {:print, "%()j"}, :custom_arg] {:ok, "{}"} @@ -30,19 +30,19 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoTest do end test "it parses the output as JSON" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:ok, "{\"title\": \"Test\"}"} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "{\"title\": \"Test\"}"} end) assert {:ok, %{"title" => "Test"}} = Video.download(@video_url) end test "it returns an error if the output is not JSON" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:ok, "Not JSON"} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "Not JSON"} end) assert {:error, %Jason.DecodeError{}} = Video.download(@video_url) end test "it directly passes along any errors" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:error, "Big issue", 1} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:error, "Big issue", 1} end) assert {:error, "Big issue", 1} = Video.download(@video_url) end diff --git a/test/pinchflat/downloader/channel_details_test.exs b/test/pinchflat/downloader/channel_details_test.exs index ba56636..cc4febd 100644 --- a/test/pinchflat/downloader/channel_details_test.exs +++ b/test/pinchflat/downloader/channel_details_test.exs @@ -17,7 +17,7 @@ defmodule Pinchflat.Downloader.ChannelDetailsTest do describe "get_channel_details/2" do test "it passes the expected arguments to the backend" do - expect(CommandRunnerMock, :run, fn @channel_url, opts -> + expect(YtDlpRunnerMock, :run, fn @channel_url, opts -> assert opts == [{:print, "%(.{channel,channel_id})j"}, {:playlist_end, 1}] {:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"} @@ -27,7 +27,7 @@ defmodule Pinchflat.Downloader.ChannelDetailsTest do end test "it returns a struct composed of the returned data" do - expect(CommandRunnerMock, :run, fn _url, _opts -> + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"} end) diff --git a/test/pinchflat/downloader/video_downloader_test.exs b/test/pinchflat/downloader/video_downloader_test.exs index 2472e95..ba9c485 100644 --- a/test/pinchflat/downloader/video_downloader_test.exs +++ b/test/pinchflat/downloader/video_downloader_test.exs @@ -14,7 +14,7 @@ defmodule Pinchflat.Downloader.VideoDownloaderTest do describe "download_for_media_profile/3" do test "it calls the backend runner with the arguments built from the media profile" do - expect(CommandRunnerMock, :run, fn @video_url, opts -> + expect(YtDlpRunnerMock, :run, fn @video_url, opts -> assert :no_simulate in opts assert {:print, "%()j"} in opts assert {:output, "/tmp/yt-dlp/videos/%(title)S.%(ext)s"} in opts @@ -26,7 +26,7 @@ defmodule Pinchflat.Downloader.VideoDownloaderTest do end test "it returns the parsed JSON output" do - expect(CommandRunnerMock, :run, fn _url, _opts -> {:ok, "{\"title\": \"Test\"}"} end) + expect(YtDlpRunnerMock, :run, fn _url, _opts -> {:ok, "{\"title\": \"Test\"}"} end) assert {:ok, %{"title" => "Test"}} = VideoDownloader.download_for_media_profile(@video_url, @media_profile) diff --git a/test/test_helper.exs b/test/test_helper.exs index 3a6890e..f3caa77 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,5 +1,5 @@ -Mox.defmock(CommandRunnerMock, for: Pinchflat.Downloader.Backends.BackendCommandRunner) -Application.put_env(:pinchflat, :yt_dlp_runner, CommandRunnerMock) +Mox.defmock(YtDlpRunnerMock, for: Pinchflat.Downloader.Backends.BackendCommandRunner) +Application.put_env(:pinchflat, :yt_dlp_runner, YtDlpRunnerMock) ExUnit.start() Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual)