0981fcdebd4de172b8823f504bdc984ce2352711
[akkoma] / test / application_requirements_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 Pleroma.RepoTest do
6 use Pleroma.DataCase
7 import ExUnit.CaptureLog
8 import Mock
9
10 describe "check_rum!" do
11 setup_with_mocks([
12 {Ecto.Migrator, [],
13 [
14 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
15 migrations: fn Pleroma.Repo -> [] end
16 ]}
17 ]) do
18 :ok
19 end
20
21 setup do: clear_config([:database, :rum_enabled])
22
23 test "raises if rum is enabled and detects unapplied rum migrations" do
24 Pleroma.Config.put([:database, :rum_enabled], true)
25
26 assert_raise Pleroma.ApplicationRequirements.VerifyError,
27 "Unapplied RUM Migrations detected",
28 fn ->
29 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
30 end
31 end
32 end
33
34 describe "check_migrations_applied!" do
35 setup_with_mocks([
36 {Ecto.Migrator, [],
37 [
38 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
39 migrations: fn Pleroma.Repo ->
40 [
41 {:up, 20_191_128_153_944, "fix_missing_following_count"},
42 {:up, 20_191_203_043_610, "create_report_notes"},
43 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
44 ]
45 end
46 ]}
47 ]) do
48 :ok
49 end
50
51 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
52
53 test "raises if it detects unapplied migrations" do
54 assert_raise Pleroma.ApplicationRequirements.VerifyError,
55 "Unapplied Migrations detected",
56 fn ->
57 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
58 end
59 end
60
61 test "doesn't do anything if disabled" do
62 Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
63
64 assert :ok == Pleroma.ApplicationRequirements.verify!()
65 end
66 end
67 end