Improved in-test config management
Reduces code duplication, improves tests structuring.
Previous code:
clear_config_all([:instance, :federation_reachability_timeout_days]) do
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
end
clear_config([:restrict_unauthenticated, :activities, :local]) do
Pleroma.Config.put([:restrict_unauthenticated, :activities, :local], true)
end
# When we needed to adjust config for a single test case
describe "(had to create context)" do
clear_config(:x) do: Pleroma.Config.put(:x, 5)
test "does what it does with x = 5" do
# ...
end
end
With this MR:
setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
test "does what it does with x = 5" do
clear_config(:x, 5)
# ...
end
[IMPLEMENTED] What we could do in future is switching to setup do: clear_config(..., ...)
in place of clear_config(..., ...)
. This way we could use the same macro for in-test and setup-level invocation (right now in-test function has to be separate, named it set_config/2
). If this switch sounds good, let me know. Pro: same function name, contra: prepending all setup-level calls with setup do:
.
Edited by Ivan Tashkinov