1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config.TransferTaskTest do
8 import ExUnit.CaptureLog
11 alias Pleroma.Config.TransferTask
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)
22 insert(:config, key: :test_key, value: [live: 2, com: 3])
23 insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35])
24 insert(:config, group: :quack, key: :test_key, value: [:test_value1, :test_value2])
25 insert(:config, group: :postgrex, key: :test_key, value: :value)
26 insert(:config, group: :logger, key: :level, value: :debug)
28 TransferTask.start_link([])
30 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
31 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
32 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
33 assert Application.get_env(:logger, :level) == :debug
34 assert Application.get_env(:postgrex, :test_key) == :value
37 Application.delete_env(:pleroma, :test_key)
38 Application.delete_env(:idna, :test_key)
39 Application.delete_env(:quack, :test_key)
40 Application.delete_env(:postgrex, :test_key)
41 Application.put_env(:logger, :level, initial)
45 test "transfer config values for 1 group and some keys" do
46 level = Application.get_env(:quack, :level)
47 meta = Application.get_env(:quack, :meta)
49 insert(:config, group: :quack, key: :level, value: :info)
50 insert(:config, group: :quack, key: :meta, value: [:none])
52 TransferTask.start_link([])
54 assert Application.get_env(:quack, :level) == :info
55 assert Application.get_env(:quack, :meta) == [:none]
56 default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
57 assert Application.get_env(:quack, :webhook_url) == default
60 Application.put_env(:quack, :level, level)
61 Application.put_env(:quack, :meta, meta)
65 test "transfer config values with full subkey update" do
69 insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
70 insert(:config, key: :assets, value: [mascots: [a: 1, b: 2]])
72 TransferTask.start_link([])
74 emoji_env = Application.get_env(:pleroma, :emoji)
75 assert emoji_env[:groups] == [a: 1, b: 2]
76 assets_env = Application.get_env(:pleroma, :assets)
77 assert assets_env[:mascots] == [a: 1, b: 2]
80 describe "pleroma restart" do
82 on_exit(fn -> Restarter.Pleroma.refresh() end)
85 test "don't restart if no reboot time settings were changed" do
87 insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
89 refute String.contains?(
90 capture_log(fn -> TransferTask.start_link([]) end),
95 test "on reboot time key" do
97 insert(:config, key: :chat, value: [enabled: false])
98 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
101 test "on reboot time subkey" do
102 clear_config(Pleroma.Captcha)
103 insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
104 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
107 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
109 clear_config(Pleroma.Captcha)
111 insert(:config, key: :chat, value: [enabled: false])
112 insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
114 refute String.contains?(
115 capture_log(fn -> TransferTask.load_and_update_env([], false) end),