Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.ConfigTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Repo
  7. alias Pleroma.Web.AdminAPI.Config
  8. setup_all do
  9. Mix.shell(Mix.Shell.Process)
  10. temp_file = "config/temp.exported_from_db.secret.exs"
  11. dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
  12. Pleroma.Config.put([:instance, :dynamic_configuration], true)
  13. on_exit(fn ->
  14. Mix.shell(Mix.Shell.IO)
  15. Application.delete_env(:pleroma, :first_setting)
  16. Application.delete_env(:pleroma, :second_setting)
  17. Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
  18. :ok = File.rm(temp_file)
  19. end)
  20. {:ok, temp_file: temp_file}
  21. end
  22. test "settings are migrated to db" do
  23. assert Repo.all(Config) == []
  24. Application.put_env(:pleroma, :first_setting, key: "value", key2: [Pleroma.Repo])
  25. Application.put_env(:pleroma, :second_setting, key: "value2", key2: [Pleroma.Activity])
  26. Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
  27. first_db = Config.get_by_params(%{group: "pleroma", key: ":first_setting"})
  28. second_db = Config.get_by_params(%{group: "pleroma", key: ":second_setting"})
  29. refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
  30. assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]]
  31. assert Config.from_binary(second_db.value) == [key: "value2", key2: [Pleroma.Activity]]
  32. end
  33. test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
  34. Config.create(%{
  35. group: "pleroma",
  36. key: ":setting_first",
  37. value: [key: "value", key2: [Pleroma.Activity]]
  38. })
  39. Config.create(%{
  40. group: "pleroma",
  41. key: ":setting_second",
  42. value: [key: "valu2", key2: [Pleroma.Repo]]
  43. })
  44. Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
  45. assert Repo.all(Config) == []
  46. assert File.exists?(temp_file)
  47. {:ok, file} = File.read(temp_file)
  48. assert file =~ "config :pleroma, :setting_first,"
  49. assert file =~ "config :pleroma, :setting_second,"
  50. end
  51. end