2019-07-10 06:13:23 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-06-14 16:45:05 +01:00
|
|
|
defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.Web.AdminAPI.Config
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
Mix.shell(Mix.Shell.Process)
|
2019-06-20 18:43:57 +01:00
|
|
|
temp_file = "config/temp.exported_from_db.secret.exs"
|
2019-06-14 16:45:05 +01:00
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
Mix.shell(Mix.Shell.IO)
|
|
|
|
Application.delete_env(:pleroma, :first_setting)
|
|
|
|
Application.delete_env(:pleroma, :second_setting)
|
|
|
|
:ok = File.rm(temp_file)
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, temp_file: temp_file}
|
|
|
|
end
|
|
|
|
|
2019-08-19 16:34:29 +01:00
|
|
|
clear_config_all([:instance, :dynamic_configuration]) do
|
|
|
|
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
|
|
|
end
|
|
|
|
|
2019-06-14 16:45:05 +01:00
|
|
|
test "settings are migrated to db" do
|
|
|
|
assert Repo.all(Config) == []
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :first_setting, key: "value", key2: [Pleroma.Repo])
|
|
|
|
Application.put_env(:pleroma, :second_setting, key: "value2", key2: [Pleroma.Activity])
|
|
|
|
|
|
|
|
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
|
|
|
|
|
2019-07-15 13:45:27 +01:00
|
|
|
first_db = Config.get_by_params(%{group: "pleroma", key: ":first_setting"})
|
|
|
|
second_db = Config.get_by_params(%{group: "pleroma", key: ":second_setting"})
|
2019-06-23 06:16:16 +01:00
|
|
|
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
|
2019-06-14 16:45:05 +01:00
|
|
|
|
|
|
|
assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]]
|
|
|
|
assert Config.from_binary(second_db.value) == [key: "value2", key2: [Pleroma.Activity]]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
|
2019-06-23 06:16:16 +01:00
|
|
|
Config.create(%{
|
|
|
|
group: "pleroma",
|
2019-07-15 13:45:27 +01:00
|
|
|
key: ":setting_first",
|
2019-06-23 06:16:16 +01:00
|
|
|
value: [key: "value", key2: [Pleroma.Activity]]
|
|
|
|
})
|
|
|
|
|
|
|
|
Config.create(%{
|
|
|
|
group: "pleroma",
|
2019-07-15 13:45:27 +01:00
|
|
|
key: ":setting_second",
|
2019-06-23 06:16:16 +01:00
|
|
|
value: [key: "valu2", key2: [Pleroma.Repo]]
|
|
|
|
})
|
2019-06-14 16:45:05 +01:00
|
|
|
|
2019-06-27 05:19:44 +01:00
|
|
|
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
|
2019-06-14 16:45:05 +01:00
|
|
|
|
|
|
|
assert Repo.all(Config) == []
|
|
|
|
assert File.exists?(temp_file)
|
|
|
|
{:ok, file} = File.read(temp_file)
|
|
|
|
|
2019-07-15 13:45:27 +01:00
|
|
|
assert file =~ "config :pleroma, :setting_first,"
|
|
|
|
assert file =~ "config :pleroma, :setting_second,"
|
2019-06-14 16:45:05 +01:00
|
|
|
end
|
|
|
|
end
|