spc-pleroma/test/tasks/config_test.exs

68 lines
2.2 KiB
Elixir
Raw Normal View History

# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
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 17:43:57 +00:00
temp_file = "config/temp.exported_from_db.secret.exs"
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 12:45:27 +00: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 05:16:16 +00:00
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
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 05:16:16 +00:00
Config.create(%{
group: "pleroma",
2019-07-15 12:45:27 +00:00
key: ":setting_first",
2019-06-23 05:16:16 +00:00
value: [key: "value", key2: [Pleroma.Activity]]
})
Config.create(%{
group: "pleroma",
2019-07-15 12:45:27 +00:00
key: ":setting_second",
2019-06-23 05:16:16 +00:00
value: [key: "valu2", key2: [Pleroma.Repo]]
})
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
assert Repo.all(Config) == []
assert File.exists?(temp_file)
{:ok, file} = File.read(temp_file)
2019-07-15 12:45:27 +00:00
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
end
end