2019-07-10 07:13:23 +02: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 17:45:05 +02: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 19:43:57 +02:00
|
|
|
temp_file = "config/temp.exported_from_db.secret.exs"
|
2019-06-14 17:45:05 +02: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 14:45:27 +02: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 07:16:16 +02:00
|
|
|
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
|
2019-06-14 17:45:05 +02: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 07:16:16 +02:00
|
|
|
Config.create(%{
|
|
|
|
group: "pleroma",
|
2019-07-15 14:45:27 +02:00
|
|
|
key: ":setting_first",
|
2019-06-23 07:16:16 +02:00
|
|
|
value: [key: "value", key2: [Pleroma.Activity]]
|
|
|
|
})
|
|
|
|
|
|
|
|
Config.create(%{
|
|
|
|
group: "pleroma",
|
2019-07-15 14:45:27 +02:00
|
|
|
key: ":setting_second",
|
2019-06-23 07:16:16 +02:00
|
|
|
value: [key: "valu2", key2: [Pleroma.Repo]]
|
|
|
|
})
|
2019-06-14 17:45:05 +02:00
|
|
|
|
2019-06-27 06:19:44 +02:00
|
|
|
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
|
2019-06-14 17:45:05 +02:00
|
|
|
|
|
|
|
assert Repo.all(Config) == []
|
|
|
|
assert File.exists?(temp_file)
|
|
|
|
{:ok, file} = File.read(temp_file)
|
|
|
|
|
2019-07-15 14:45:27 +02:00
|
|
|
assert file =~ "config :pleroma, :setting_first,"
|
|
|
|
assert file =~ "config :pleroma, :setting_second,"
|
2019-06-14 17:45:05 +02:00
|
|
|
end
|
|
|
|
end
|