[#3251] Fixed wrong test-env config setting for [Pleroma.Upload]. Refactoring. Added warning to clear_config/_ to minimize such issues in future.

This commit is contained in:
Ivan Tashkinov 2021-01-16 23:05:31 +03:00
commit 3f88e33a71
6 changed files with 35 additions and 33 deletions

View file

@ -8,6 +8,8 @@ defmodule Pleroma.Tests.Helpers do
"""
alias Pleroma.Config
require Logger
defmacro clear_config(config_path) do
quote do
clear_config(unquote(config_path)) do
@ -18,6 +20,7 @@ defmodule Pleroma.Tests.Helpers do
defmacro clear_config(config_path, do: yield) do
quote do
initial_setting = Config.fetch(unquote(config_path))
unquote(yield)
on_exit(fn ->
@ -35,6 +38,15 @@ defmodule Pleroma.Tests.Helpers do
end
defmacro clear_config(config_path, temp_setting) do
# NOTE: `clear_config([section, key], value)` != `clear_config([section], key: value)` (!)
# Displaying a warning to prevent unintentional clearing of all but one keys in section
if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do
Logger.warn(
"Please change to `clear_config([section]); clear_config([section, key], value)`: " <>
"#{inspect(config_path)}, #{inspect(temp_setting)}"
)
end
quote do
clear_config(unquote(config_path)) do
Config.put(unquote(config_path), unquote(temp_setting))