Renamed CommandRunnerMock to have a more descriptive name
This commit is contained in:
parent
94ca11001b
commit
d664e828b8
6 changed files with 19 additions and 19 deletions
|
|
@ -11,7 +11,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.ChannelTest do
|
||||||
|
|
||||||
describe "get_channel_info/1" do
|
describe "get_channel_info/1" do
|
||||||
test "it returns a %ChannelDetails{} with data on success" 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\"}"}
|
{:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.ChannelTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it passes the expected args to the backend runner" do
|
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}]
|
assert opts == [{:print, "%(.{channel,channel_id})j"}, {:playlist_end, 1}]
|
||||||
|
|
||||||
{:ok, "{}"}
|
{:ok, "{}"}
|
||||||
|
|
@ -30,13 +30,13 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.ChannelTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns an error if the runner returns an error" do
|
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)
|
assert {:error, "Big issue", 1} = Channel.get_channel_info(@channel_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns an error if the output is not JSON" do
|
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)
|
assert {:error, %Jason.DecodeError{}} = Channel.get_channel_info(@channel_url)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoCollectionTest do
|
||||||
|
|
||||||
describe "get_video_ids/2" do
|
describe "get_video_ids/2" do
|
||||||
test "returns a list of video ids with no blank elements" 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)
|
assert {:ok, ["id1", "id2", "id3"]} = VideoCollectionUser.get_video_ids(@channel_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it passes the expected default args" do
|
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}]
|
assert opts == [:simulate, :skip_download, {:print, :id}]
|
||||||
|
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoCollectionTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it passes the expected custom args" do
|
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}]
|
assert opts == [:custom_arg, :simulate, :skip_download, {:print, :id}]
|
||||||
|
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
|
|
@ -40,7 +40,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoCollectionTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns the error straight through when the command fails" do
|
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)
|
assert {:error, "Big issue", 1} = VideoCollectionUser.get_video_ids(@channel_url)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoTest do
|
||||||
|
|
||||||
describe "download/2" do
|
describe "download/2" do
|
||||||
test "it calls the backend runner with the expected arguments" 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"}]
|
assert opts == [:no_simulate, {:print, "%()j"}]
|
||||||
|
|
||||||
{:ok, "{}"}
|
{:ok, "{}"}
|
||||||
|
|
@ -20,7 +20,7 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it passes along additional options" do
|
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]
|
assert opts == [:no_simulate, {:print, "%()j"}, :custom_arg]
|
||||||
|
|
||||||
{:ok, "{}"}
|
{:ok, "{}"}
|
||||||
|
|
@ -30,19 +30,19 @@ defmodule Pinchflat.Downloader.Backends.YtDlp.VideoTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it parses the output as JSON" do
|
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)
|
assert {:ok, %{"title" => "Test"}} = Video.download(@video_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns an error if the output is not JSON" do
|
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)
|
assert {:error, %Jason.DecodeError{}} = Video.download(@video_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it directly passes along any errors" do
|
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)
|
assert {:error, "Big issue", 1} = Video.download(@video_url)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ defmodule Pinchflat.Downloader.ChannelDetailsTest do
|
||||||
|
|
||||||
describe "get_channel_details/2" do
|
describe "get_channel_details/2" do
|
||||||
test "it passes the expected arguments to the backend" 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}]
|
assert opts == [{:print, "%(.{channel,channel_id})j"}, {:playlist_end, 1}]
|
||||||
|
|
||||||
{:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"}
|
{:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"}
|
||||||
|
|
@ -27,7 +27,7 @@ defmodule Pinchflat.Downloader.ChannelDetailsTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns a struct composed of the returned data" do
|
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\"}"}
|
{:ok, "{\"channel\": \"TheUselessTrials\", \"channel_id\": \"UCQH2\"}"}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ defmodule Pinchflat.Downloader.VideoDownloaderTest do
|
||||||
|
|
||||||
describe "download_for_media_profile/3" do
|
describe "download_for_media_profile/3" do
|
||||||
test "it calls the backend runner with the arguments built from the media profile" 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 :no_simulate in opts
|
||||||
assert {:print, "%()j"} in opts
|
assert {:print, "%()j"} in opts
|
||||||
assert {:output, "/tmp/yt-dlp/videos/%(title)S.%(ext)s"} in opts
|
assert {:output, "/tmp/yt-dlp/videos/%(title)S.%(ext)s"} in opts
|
||||||
|
|
@ -26,7 +26,7 @@ defmodule Pinchflat.Downloader.VideoDownloaderTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns the parsed JSON output" do
|
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"}} =
|
assert {:ok, %{"title" => "Test"}} =
|
||||||
VideoDownloader.download_for_media_profile(@video_url, @media_profile)
|
VideoDownloader.download_for_media_profile(@video_url, @media_profile)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Mox.defmock(CommandRunnerMock, for: Pinchflat.Downloader.Backends.BackendCommandRunner)
|
Mox.defmock(YtDlpRunnerMock, for: Pinchflat.Downloader.Backends.BackendCommandRunner)
|
||||||
Application.put_env(:pinchflat, :yt_dlp_runner, CommandRunnerMock)
|
Application.put_env(:pinchflat, :yt_dlp_runner, YtDlpRunnerMock)
|
||||||
|
|
||||||
ExUnit.start()
|
ExUnit.start()
|
||||||
Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual)
|
Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue