summaryrefslogtreecommitdiff
path: root/test/support/helpers.ex
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-03-18 20:30:31 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-03-18 20:30:31 +0300
commitec3719f5391d6f9945cec2e36287049d72743cd4 (patch)
tree6be0c45d7168d47491e4d49a4ad558e9cd335990 /test/support/helpers.ex
parent69341cbcbac2459faa43bb924577e84dac353982 (diff)
downloadpleroma-ec3719f5391d6f9945cec2e36287049d72743cd4.tar.gz
pleroma-ec3719f5391d6f9945cec2e36287049d72743cd4.zip
Improved in-test config management functions.
Diffstat (limited to 'test/support/helpers.ex')
-rw-r--r--test/support/helpers.ex30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 6bf4b019e..c6f7fa5e2 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -26,6 +26,25 @@ defmodule Pleroma.Tests.Helpers do
end
end
+ defmacro clear_config(config_path, temp_setting) do
+ quote do
+ clear_config(unquote(config_path)) do
+ Config.put(unquote(config_path), unquote(temp_setting))
+ end
+ end
+ end
+
+ @doc """
+ From _within a test case_, sets config to provided value and restores initial value on exit.
+ For multi-case setup use `clear_config/2` instead.
+ """
+ def set_config(config_path, temp_setting) do
+ initial_setting = Config.get(config_path)
+ Config.put(config_path, temp_setting)
+
+ ExUnit.Callbacks.on_exit(fn -> Config.put(config_path, initial_setting) end)
+ end
+
@doc "Stores initial config value and restores it after *all* test examples are executed."
defmacro clear_config_all(config_path) do
quote do
@@ -50,6 +69,14 @@ defmodule Pleroma.Tests.Helpers do
end
end
+ defmacro clear_config_all(config_path, temp_setting) do
+ quote do
+ clear_config_all(unquote(config_path)) do
+ Config.put(unquote(config_path), unquote(temp_setting))
+ end
+ end
+ end
+
defmacro __using__(_opts) do
quote do
import Pleroma.Tests.Helpers,
@@ -57,7 +84,8 @@ defmodule Pleroma.Tests.Helpers do
clear_config: 1,
clear_config: 2,
clear_config_all: 1,
- clear_config_all: 2
+ clear_config_all: 2,
+ set_config: 2
]
def to_datetime(naive_datetime) do