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