Remove the debugging IO.inspect
[akkoma] / test / tasks / uploads_test.exs
1 defmodule Mix.Tasks.Pleroma.UploadsTest do
2 alias Pleroma.Upload
3 use Pleroma.DataCase
4
5 import Mock
6
7 setup_all do
8 Mix.shell(Mix.Shell.Process)
9
10 on_exit(fn ->
11 Mix.shell(Mix.Shell.IO)
12 end)
13
14 :ok
15 end
16
17 describe "running migrate_local" do
18 test "uploads migrated" do
19 with_mock Upload,
20 store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do
21 Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"])
22
23 assert_received {:mix_shell, :info, [message]}
24 assert message =~ "Migrating files from local"
25
26 assert_received {:mix_shell, :info, [message]}
27
28 assert %{"total_count" => total_count} =
29 Regex.named_captures(~r"^Found (?<total_count>\d+) uploads$", message)
30
31 assert_received {:mix_shell, :info, [message]}
32
33 # @logevery in Mix.Tasks.Pleroma.Uploads
34 count =
35 min(50, String.to_integer(total_count))
36 |> to_string()
37
38 assert %{"count" => ^count, "total_count" => ^total_count} =
39 Regex.named_captures(
40 ~r"^Uploaded (?<count>\d+)/(?<total_count>\d+) files$",
41 message
42 )
43 end
44 end
45
46 test "nonexistent uploader" do
47 assert_raise RuntimeError, ~r/The uploader .* is not an existing/, fn ->
48 Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "nonexistent"])
49 end
50 end
51 end
52 end