Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

97 lines
3.1KB

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