2019-07-09 23:13:23 -06: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 09:45:05 -06: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 11:43:57 -06:00
|
|
|
temp_file = "config/temp.exported_from_db.secret.exs"
|
2019-06-14 09:45:05 -06:00
|
|
|
|
|
|
|
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
|
|
|
|
|
|
|
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
Mix.shell(Mix.Shell.IO)
|
|
|
|
Application.delete_env(:pleroma, :first_setting)
|
|
|
|
Application.delete_env(:pleroma, :second_setting)
|
|
|
|
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
|
|
|
:ok = File.rm(temp_file)
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, temp_file: temp_file}
|
|
|
|
end
|
|
|
|
|
|
|
|
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 06:45:27 -06: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-22 23:16:16 -06:00
|
|
|
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
|
2019-06-14 09:45:05 -06: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-22 23:16:16 -06:00
|
|
|
Config.create(%{
|
|
|
|
group: "pleroma",
|
2019-07-15 06:45:27 -06:00
|
|
|
key: ":setting_first",
|
2019-06-22 23:16:16 -06:00
|
|
|
value: [key: "value", key2: [Pleroma.Activity]]
|
|
|
|
})
|
|
|
|
|
|
|
|
Config.create(%{
|
|
|
|
group: "pleroma",
|
2019-07-15 06:45:27 -06:00
|
|
|
key: ":setting_second",
|
2019-06-22 23:16:16 -06:00
|
|
|
value: [key: "valu2", key2: [Pleroma.Repo]]
|
|
|
|
})
|
2019-06-14 09:45:05 -06:00
|
|
|
|
2019-06-26 22:19:44 -06:00
|
|
|
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
|
2019-06-14 09:45:05 -06:00
|
|
|
|
|
|
|
assert Repo.all(Config) == []
|
|
|
|
assert File.exists?(temp_file)
|
|
|
|
{:ok, file} = File.read(temp_file)
|
|
|
|
|
2019-07-15 06:45:27 -06:00
|
|
|
assert file =~ "config :pleroma, :setting_first,"
|
|
|
|
assert file =~ "config :pleroma, :setting_second,"
|
2019-06-14 09:45:05 -06:00
|
|
|
end
|
|
|
|
end
|