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)
23 value: [live: 2, com: 3]
29 value: [live: 15, com: 35]
35 value: [:test_value1, :test_value2]
38 TransferTask.start_link([])
40 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
41 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
42 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
45 Application.delete_env(:pleroma, :test_key)
46 Application.delete_env(:idna, :test_key)
47 Application.delete_env(:quack, :test_key)
51 test "transfer config values for 1 group and some keys" do
52 level = Application.get_env(:quack, :level)
53 meta = Application.get_env(:quack, :meta)
67 TransferTask.start_link([])
69 assert Application.get_env(:quack, :level) == :info
70 assert Application.get_env(:quack, :meta) == [:none]
71 default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
72 assert Application.get_env(:quack, :webhook_url) == default
75 Application.put_env(:quack, :level, level)
76 Application.put_env(:quack, :meta, meta)
80 test "transfer config values with full subkey update" do
81 emoji = Application.get_env(:pleroma, :emoji)
82 assets = Application.get_env(:pleroma, :assets)
87 value: [groups: [a: 1, b: 2]]
93 value: [mascots: [a: 1, b: 2]]
96 TransferTask.start_link([])
98 emoji_env = Application.get_env(:pleroma, :emoji)
99 assert emoji_env[:groups] == [a: 1, b: 2]
100 assets_env = Application.get_env(:pleroma, :assets)
101 assert assets_env[:mascots] == [a: 1, b: 2]
104 Application.put_env(:pleroma, :emoji, emoji)
105 Application.put_env(:pleroma, :assets, assets)
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
115 emoji = Application.get_env(:pleroma, :emoji)
116 on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
121 value: [groups: [a: 1, b: 2]]
124 refute String.contains?(
125 capture_log(fn -> TransferTask.start_link([]) end),
130 test "on reboot time key" do
131 chat = Application.get_env(:pleroma, :chat)
132 on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
137 value: [enabled: false]
140 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
143 test "on reboot time subkey" do
144 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
145 on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
149 key: "Pleroma.Captcha",
150 value: [seconds_valid: 60]
153 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
156 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
157 chat = Application.get_env(:pleroma, :chat)
158 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
161 Application.put_env(:pleroma, :chat, chat)
162 Application.put_env(:pleroma, Pleroma.Captcha, captcha)
168 value: [enabled: false]
173 key: "Pleroma.Captcha",
174 value: [seconds_valid: 60]
177 refute String.contains?(
178 capture_log(fn -> TransferTask.load_and_update_env([], false) end),