Improved in-test config management functions.
This commit is contained in:
parent
69341cbcba
commit
ec3719f539
32 changed files with 89 additions and 155 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue