1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 clear_config(:configurable_from_database) do
14 Pleroma.Config.put(:configurable_from_database, true)
17 test "transfer config values from db to env" do
18 refute Application.get_env(:pleroma, :test_key)
19 refute Application.get_env(:idna, :test_key)
20 refute Application.get_env(:quack, :test_key)
25 value: [live: 2, com: 3]
31 value: [live: 15, com: 35]
37 value: [:test_value1, :test_value2]
40 TransferTask.start_link([])
42 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
43 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
44 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
47 Application.delete_env(:pleroma, :test_key)
48 Application.delete_env(:idna, :test_key)
49 Application.delete_env(:quack, :test_key)
53 test "transfer config values for 1 group and some keys" do
54 level = Application.get_env(:quack, :level)
55 meta = Application.get_env(:quack, :meta)
69 TransferTask.start_link([])
71 assert Application.get_env(:quack, :level) == :info
72 assert Application.get_env(:quack, :meta) == [:none]
73 default = Pleroma.Config.Holder.config(:quack, :webhook_url)
74 assert Application.get_env(:quack, :webhook_url) == default
77 Application.put_env(:quack, :level, level)
78 Application.put_env(:quack, :meta, meta)
82 test "transfer config values with full subkey update" do
83 emoji = Application.get_env(:pleroma, :emoji)
84 assets = Application.get_env(:pleroma, :assets)
89 value: [groups: [a: 1, b: 2]]
95 value: [mascots: [a: 1, b: 2]]
98 TransferTask.start_link([])
100 emoji_env = Application.get_env(:pleroma, :emoji)
101 assert emoji_env[:groups] == [a: 1, b: 2]
102 assets_env = Application.get_env(:pleroma, :assets)
103 assert assets_env[:mascots] == [a: 1, b: 2]
106 Application.put_env(:pleroma, :emoji, emoji)
107 Application.put_env(:pleroma, :assets, assets)
111 describe "pleroma restart" do
112 test "don't restart if no reboot time settings were changed" do
113 emoji = Application.get_env(:pleroma, :emoji)
114 on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
119 value: [groups: [a: 1, b: 2]]
122 refute String.contains?(
123 capture_log(fn -> TransferTask.start_link([]) end),
128 test "restart pleroma on reboot time key" do
129 chat = Application.get_env(:pleroma, :chat)
130 on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
135 value: [enabled: false]
138 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
141 test "restart pleroma on reboot time subkey" do
142 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
143 on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
147 key: "Pleroma.Captcha",
148 value: [seconds_valid: 60]
151 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
154 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
155 chat = Application.get_env(:pleroma, :chat)
156 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
159 Application.put_env(:pleroma, :chat, chat)
160 Application.put_env(:pleroma, Pleroma.Captcha, captcha)
166 value: [enabled: false]
171 key: "Pleroma.Captcha",
172 value: [seconds_valid: 60]
175 refute String.contains?(
176 capture_log(fn -> TransferTask.load_and_update_env([], false) end),