Add failing test, which exposes a bug
[akkoma] / test / config_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.ConfigTest do
6 use ExUnit.Case
7
8 test "get/1 with an atom" do
9 assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance)
10 assert Pleroma.Config.get(:azertyuiop) == nil
11 assert Pleroma.Config.get(:azertyuiop, true) == true
12 end
13
14 test "get/1 with a list of keys" do
15 assert Pleroma.Config.get([:instance, :public]) ==
16 Keyword.get(Application.get_env(:pleroma, :instance), :public)
17
18 assert Pleroma.Config.get([Pleroma.Web.Endpoint, :render_errors, :view]) ==
19 get_in(
20 Application.get_env(
21 :pleroma,
22 Pleroma.Web.Endpoint
23 ),
24 [:render_errors, :view]
25 )
26
27 assert Pleroma.Config.get([:azerty, :uiop]) == nil
28 assert Pleroma.Config.get([:azerty, :uiop], true) == true
29 end
30
31 test "get/1 when value is false" do
32 Pleroma.Config.put([:instance, :false_test], false)
33 Pleroma.Config.put([:instance, :nested], [])
34 Pleroma.Config.put([:instance, :nested, :false_test], false)
35
36 assert Pleroma.Config.get([:instance, :false_test]) == false
37 assert Pleroma.Config.get([:instance, :nested, :false_test]) == false
38 end
39
40 test "get!/1" do
41 assert Pleroma.Config.get!(:instance) == Application.get_env(:pleroma, :instance)
42
43 assert Pleroma.Config.get!([:instance, :public]) ==
44 Keyword.get(Application.get_env(:pleroma, :instance), :public)
45
46 assert_raise(Pleroma.Config.Error, fn ->
47 Pleroma.Config.get!(:azertyuiop)
48 end)
49
50 assert_raise(Pleroma.Config.Error, fn ->
51 Pleroma.Config.get!([:azerty, :uiop])
52 end)
53 end
54
55 test "get!/1 when value is false" do
56 Pleroma.Config.put([:instance, :false_test], false)
57 Pleroma.Config.put([:instance, :nested], [])
58 Pleroma.Config.put([:instance, :nested, :false_test], false)
59
60 assert Pleroma.Config.get!([:instance, :false_test]) == false
61 assert Pleroma.Config.get!([:instance, :nested, :false_test]) == false
62 end
63
64 test "put/2 with a key" do
65 Pleroma.Config.put(:config_test, true)
66
67 assert Pleroma.Config.get(:config_test) == true
68 end
69
70 test "put/2 with a list of keys" do
71 Pleroma.Config.put([:instance, :config_test], true)
72 Pleroma.Config.put([:instance, :config_nested_test], [])
73 Pleroma.Config.put([:instance, :config_nested_test, :x], true)
74
75 assert Pleroma.Config.get([:instance, :config_test]) == true
76 assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
77 end
78
79 test "delete/1 with a key" do
80 Pleroma.Config.put([:delete_me], :delete_me)
81 Pleroma.Config.delete([:delete_me])
82 assert Pleroma.Config.get([:delete_me]) == nil
83 end
84
85 test "delete/2 with a list of keys" do
86 Pleroma.Config.put([:delete_me], hello: "world", world: "Hello")
87 Pleroma.Config.delete([:delete_me, :world])
88 assert Pleroma.Config.get([:delete_me]) == [hello: "world"]
89 Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
90 Pleroma.Config.delete([:delete_me, :delete_me, :world])
91 assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
92 end
93 end