1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config.TransferTaskTest do
8 import ExUnit.CaptureLog
10 alias Pleroma.Config.TransferTask
11 alias Pleroma.ConfigDB
13 setup do: clear_config(:configurable_from_database, true)
15 test "transfer config values from db to env" do
16 refute Application.get_env(:pleroma, :test_key)
17 refute Application.get_env(:idna, :test_key)
18 refute Application.get_env(:quack, :test_key)
19 refute Application.get_env(:postgrex, :test_key)
20 initial = Application.get_env(:logger, :level)
25 value: [live: 2, com: 3]
31 value: [live: 15, com: 35]
37 value: [:test_value1, :test_value2]
46 ConfigDB.create(%{group: ":logger", key: ":level", value: :debug})
48 TransferTask.start_link([])
50 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
51 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
52 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
53 assert Application.get_env(:logger, :level) == :debug
54 assert Application.get_env(:postgrex, :test_key) == :value
57 Application.delete_env(:pleroma, :test_key)
58 Application.delete_env(:idna, :test_key)
59 Application.delete_env(:quack, :test_key)
60 Application.delete_env(:postgrex, :test_key)
61 Application.put_env(:logger, :level, initial)
65 test "transfer config values for 1 group and some keys" do
66 level = Application.get_env(:quack, :level)
67 meta = Application.get_env(:quack, :meta)
81 TransferTask.start_link([])
83 assert Application.get_env(:quack, :level) == :info
84 assert Application.get_env(:quack, :meta) == [:none]
85 default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
86 assert Application.get_env(:quack, :webhook_url) == default
89 Application.put_env(:quack, :level, level)
90 Application.put_env(:quack, :meta, meta)
94 test "transfer config values with full subkey update" do
101 value: [groups: [a: 1, b: 2]]
107 value: [mascots: [a: 1, b: 2]]
110 TransferTask.start_link([])
112 emoji_env = Application.get_env(:pleroma, :emoji)
113 assert emoji_env[:groups] == [a: 1, b: 2]
114 assets_env = Application.get_env(:pleroma, :assets)
115 assert assets_env[:mascots] == [a: 1, b: 2]
118 describe "pleroma restart" do
120 on_exit(fn -> Restarter.Pleroma.refresh() end)
123 test "don't restart if no reboot time settings were changed" do
129 value: [groups: [a: 1, b: 2]]
132 refute String.contains?(
133 capture_log(fn -> TransferTask.start_link([]) end),
138 test "on reboot time key" do
144 value: [enabled: false]
147 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
150 test "on reboot time subkey" do
151 clear_config(Pleroma.Captcha)
155 key: "Pleroma.Captcha",
156 value: [seconds_valid: 60]
159 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
162 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
164 clear_config(Pleroma.Captcha)
169 value: [enabled: false]
174 key: "Pleroma.Captcha",
175 value: [seconds_valid: 60]
178 refute String.contains?(
179 capture_log(fn -> TransferTask.load_and_update_env([], false) end),