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 alias Pleroma.Config.TransferTask
11 clear_config(:configurable_from_database) do
12 Pleroma.Config.put(: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.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 test "non existing atom" do
112 key: ":undefined_atom_key",
113 value: [live: 2, com: 3]
116 assert ExUnit.CaptureLog.capture_log(fn ->
117 TransferTask.start_link([])
119 "updating env causes error, group: \":pleroma\", key: \":undefined_atom_key\", value: [live: 2, com: 3], error: %ArgumentError{message: \"argument error\"}"