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.ConfigTest do
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
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)
18 assert Pleroma.Config.get([Pleroma.Web.Endpoint, :render_errors, :view]) ==
24 [:render_errors, :view]
27 assert Pleroma.Config.get([:azerty, :uiop]) == nil
28 assert Pleroma.Config.get([:azerty, :uiop], true) == true
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)
36 assert Pleroma.Config.get([:instance, :false_test]) == false
37 assert Pleroma.Config.get([:instance, :nested, :false_test]) == false
41 assert Pleroma.Config.get!(:instance) == Application.get_env(:pleroma, :instance)
43 assert Pleroma.Config.get!([:instance, :public]) ==
44 Keyword.get(Application.get_env(:pleroma, :instance), :public)
46 assert_raise(Pleroma.Config.Error, fn ->
47 Pleroma.Config.get!(:azertyuiop)
50 assert_raise(Pleroma.Config.Error, fn ->
51 Pleroma.Config.get!([:azerty, :uiop])
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)
60 assert Pleroma.Config.get!([:instance, :false_test]) == false
61 assert Pleroma.Config.get!([:instance, :nested, :false_test]) == false
64 test "put/2 with a key" do
65 Pleroma.Config.put(:config_test, true)
67 assert Pleroma.Config.get(:config_test) == true
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)
75 assert Pleroma.Config.get([:instance, :config_test]) == true
76 assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
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
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"]