X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fconfig_test.exs;h=1556e4237420cf35c253f7a19f43b7b57495dca6;hb=cb29769a224104882ed7572087f8cd2db48475ef;hp=438fe62eedf31b004df767dff7d14249a56fdc5c;hpb=fd48bd80eb7eab563c25586b1deba2ed42c02c5a;p=akkoma
diff --git a/test/config_test.exs b/test/config_test.exs
index 438fe62ee..1556e4237 100644
--- a/test/config_test.exs
+++ b/test/config_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConfigTest do
@@ -28,6 +28,34 @@ defmodule Pleroma.ConfigTest do
assert Pleroma.Config.get([:azerty, :uiop], true) == true
end
+ describe "nil values" do
+ setup do
+ Pleroma.Config.put(:lorem, nil)
+ Pleroma.Config.put(:ipsum, %{dolor: [sit: nil]})
+ Pleroma.Config.put(:dolor, sit: %{amet: nil})
+
+ on_exit(fn -> Enum.each(~w(lorem ipsum dolor)a, &Pleroma.Config.delete/1) end)
+ end
+
+ test "get/1 with an atom for nil value" do
+ assert Pleroma.Config.get(:lorem) == nil
+ end
+
+ test "get/2 with an atom for nil value" do
+ assert Pleroma.Config.get(:lorem, true) == nil
+ end
+
+ test "get/1 with a list of keys for nil value" do
+ assert Pleroma.Config.get([:ipsum, :dolor, :sit]) == nil
+ assert Pleroma.Config.get([:dolor, :sit, :amet]) == nil
+ end
+
+ test "get/2 with a list of keys for nil value" do
+ assert Pleroma.Config.get([:ipsum, :dolor, :sit], true) == nil
+ assert Pleroma.Config.get([:dolor, :sit, :amet], true) == nil
+ end
+ end
+
test "get/1 when value is false" do
Pleroma.Config.put([:instance, :false_test], false)
Pleroma.Config.put([:instance, :nested], [])
@@ -89,5 +117,23 @@ defmodule Pleroma.ConfigTest do
Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
Pleroma.Config.delete([:delete_me, :delete_me, :world])
assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
+
+ assert Pleroma.Config.delete([:this_key_does_not_exist])
+ assert Pleroma.Config.delete([:non, :existing, :key])
+ end
+
+ test "fetch/1" do
+ Pleroma.Config.put([:lorem], :ipsum)
+ Pleroma.Config.put([:ipsum], dolor: :sit)
+
+ assert Pleroma.Config.fetch([:lorem]) == {:ok, :ipsum}
+ assert Pleroma.Config.fetch(:lorem) == {:ok, :ipsum}
+ assert Pleroma.Config.fetch([:ipsum, :dolor]) == {:ok, :sit}
+ assert Pleroma.Config.fetch([:lorem, :ipsum]) == :error
+ assert Pleroma.Config.fetch([:loremipsum]) == :error
+ assert Pleroma.Config.fetch(:loremipsum) == :error
+
+ Pleroma.Config.delete([:lorem])
+ Pleroma.Config.delete([:ipsum])
end
end