Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / config / transfer_task_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Config.TransferTaskTest do
6 use Pleroma.DataCase
7
8 clear_config([:instance, :dynamic_configuration]) do
9 Pleroma.Config.put([:instance, :dynamic_configuration], true)
10 end
11
12 test "transfer config values from db to env" do
13 refute Application.get_env(:pleroma, :test_key)
14 refute Application.get_env(:idna, :test_key)
15
16 Pleroma.Web.AdminAPI.Config.create(%{
17 group: "pleroma",
18 key: "test_key",
19 value: [live: 2, com: 3]
20 })
21
22 Pleroma.Web.AdminAPI.Config.create(%{
23 group: "idna",
24 key: "test_key",
25 value: [live: 15, com: 35]
26 })
27
28 Pleroma.Config.TransferTask.start_link([])
29
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
33 on_exit(fn ->
34 Application.delete_env(:pleroma, :test_key)
35 Application.delete_env(:idna, :test_key)
36 end)
37 end
38
39 test "non existing atom" do
40 Pleroma.Web.AdminAPI.Config.create(%{
41 group: "pleroma",
42 key: "undefined_atom_key",
43 value: [live: 2, com: 3]
44 })
45
46 assert ExUnit.CaptureLog.capture_log(fn ->
47 Pleroma.Config.TransferTask.start_link([])
48 end) =~
49 "updating env causes error, key: \"undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
50 end
51 end