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 initial = Application.get_env(:logger, :level)
24 value: [live: 2, com: 3]
30 value: [live: 15, com: 35]
36 value: [:test_value1, :test_value2]
39 ConfigDB.create(%{group: ":logger", key: ":level", value: :debug})
41 TransferTask.start_link([])
43 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
44 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
45 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
46 assert Application.get_env(:logger, :level) == :debug
49 Application.delete_env(:pleroma, :test_key)
50 Application.delete_env(:idna, :test_key)
51 Application.delete_env(:quack, :test_key)
52 Application.put_env(:logger, :level, initial)
56 test "transfer config values for 1 group and some keys" do
57 level = Application.get_env(:quack, :level)
58 meta = Application.get_env(:quack, :meta)
72 TransferTask.start_link([])
74 assert Application.get_env(:quack, :level) == :info
75 assert Application.get_env(:quack, :meta) == [:none]
76 default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
77 assert Application.get_env(:quack, :webhook_url) == default
80 Application.put_env(:quack, :level, level)
81 Application.put_env(:quack, :meta, meta)
85 test "transfer config values with full subkey update" do
92 value: [groups: [a: 1, b: 2]]
98 value: [mascots: [a: 1, b: 2]]
101 TransferTask.start_link([])
103 emoji_env = Application.get_env(:pleroma, :emoji)
104 assert emoji_env[:groups] == [a: 1, b: 2]
105 assets_env = Application.get_env(:pleroma, :assets)
106 assert assets_env[:mascots] == [a: 1, b: 2]
109 describe "pleroma restart" do
111 on_exit(fn -> Restarter.Pleroma.refresh() end)
114 test "don't restart if no reboot time settings were changed" do
120 value: [groups: [a: 1, b: 2]]
123 refute String.contains?(
124 capture_log(fn -> TransferTask.start_link([]) end),
129 test "on reboot time key" do
135 value: [enabled: false]
138 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
141 test "on reboot time subkey" do
142 clear_config(Pleroma.Captcha)
146 key: "Pleroma.Captcha",
147 value: [seconds_valid: 60]
150 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
153 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
155 clear_config(Pleroma.Captcha)
160 value: [enabled: false]
165 key: "Pleroma.Captcha",
166 value: [seconds_valid: 60]
169 refute String.contains?(
170 capture_log(fn -> TransferTask.load_and_update_env([], false) end),