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 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
113 on_exit(fn -> Restarter.Pleroma.refresh() end)
116 test "don't restart if no reboot time settings were changed" do
117 emoji = Application.get_env(:pleroma, :emoji)
118 on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
123 value: [groups: [a: 1, b: 2]]
126 refute String.contains?(
127 capture_log(fn -> TransferTask.start_link([]) end),
132 test "on reboot time key" do
133 chat = Application.get_env(:pleroma, :chat)
134 on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
139 value: [enabled: false]
142 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
145 test "on reboot time subkey" do
146 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
147 on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
151 key: "Pleroma.Captcha",
152 value: [seconds_valid: 60]
155 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
158 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
159 chat = Application.get_env(:pleroma, :chat)
160 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
163 Application.put_env(:pleroma, :chat, chat)
164 Application.put_env(:pleroma, Pleroma.Captcha, captcha)
170 value: [enabled: false]
175 key: "Pleroma.Captcha",
176 value: [seconds_valid: 60]
179 refute String.contains?(
180 capture_log(fn -> TransferTask.load_and_update_env([], false) end),