Merge branch 'develop' into 'remove-twitter-api'
[akkoma] / test / config / transfer_task_test.exs
index ce31d1e877c35eb81cde8422a965d35a42c006cf..473899d1d57e1ecf5a74548562a6659a638b0385 100644 (file)
@@ -10,14 +10,14 @@ defmodule Pleroma.Config.TransferTaskTest do
   alias Pleroma.Config.TransferTask
   alias Pleroma.ConfigDB
 
   alias Pleroma.Config.TransferTask
   alias Pleroma.ConfigDB
 
-  clear_config(:configurable_from_database) do
-    Pleroma.Config.put(:configurable_from_database, true)
-  end
+  setup do: clear_config(:configurable_from_database, true)
 
   test "transfer config values from db to env" do
     refute Application.get_env(:pleroma, :test_key)
     refute Application.get_env(:idna, :test_key)
     refute Application.get_env(:quack, :test_key)
 
   test "transfer config values from db to env" do
     refute Application.get_env(:pleroma, :test_key)
     refute Application.get_env(:idna, :test_key)
     refute Application.get_env(:quack, :test_key)
+    refute Application.get_env(:postgrex, :test_key)
+    initial = Application.get_env(:logger, :level)
 
     ConfigDB.create(%{
       group: ":pleroma",
 
     ConfigDB.create(%{
       group: ":pleroma",
@@ -37,16 +37,28 @@ defmodule Pleroma.Config.TransferTaskTest do
       value: [:test_value1, :test_value2]
     })
 
       value: [:test_value1, :test_value2]
     })
 
+    ConfigDB.create(%{
+      group: ":postgrex",
+      key: ":test_key",
+      value: :value
+    })
+
+    ConfigDB.create(%{group: ":logger", key: ":level", value: :debug})
+
     TransferTask.start_link([])
 
     assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
     assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
     assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
     TransferTask.start_link([])
 
     assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
     assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
     assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
+    assert Application.get_env(:logger, :level) == :debug
+    assert Application.get_env(:postgrex, :test_key) == :value
 
     on_exit(fn ->
       Application.delete_env(:pleroma, :test_key)
       Application.delete_env(:idna, :test_key)
       Application.delete_env(:quack, :test_key)
 
     on_exit(fn ->
       Application.delete_env(:pleroma, :test_key)
       Application.delete_env(:idna, :test_key)
       Application.delete_env(:quack, :test_key)
+      Application.delete_env(:postgrex, :test_key)
+      Application.put_env(:logger, :level, initial)
     end)
   end
 
     end)
   end
 
@@ -70,7 +82,7 @@ defmodule Pleroma.Config.TransferTaskTest do
 
     assert Application.get_env(:quack, :level) == :info
     assert Application.get_env(:quack, :meta) == [:none]
 
     assert Application.get_env(:quack, :level) == :info
     assert Application.get_env(:quack, :meta) == [:none]
-    default = Pleroma.Config.Holder.config(:quack, :webhook_url)
+    default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
     assert Application.get_env(:quack, :webhook_url) == default
 
     on_exit(fn ->
     assert Application.get_env(:quack, :webhook_url) == default
 
     on_exit(fn ->
@@ -80,8 +92,8 @@ defmodule Pleroma.Config.TransferTaskTest do
   end
 
   test "transfer config values with full subkey update" do
   end
 
   test "transfer config values with full subkey update" do
-    emoji = Application.get_env(:pleroma, :emoji)
-    assets = Application.get_env(:pleroma, :assets)
+    clear_config(:emoji)
+    clear_config(:assets)
 
     ConfigDB.create(%{
       group: ":pleroma",
 
     ConfigDB.create(%{
       group: ":pleroma",
@@ -101,11 +113,6 @@ defmodule Pleroma.Config.TransferTaskTest do
     assert emoji_env[:groups] == [a: 1, b: 2]
     assets_env = Application.get_env(:pleroma, :assets)
     assert assets_env[:mascots] == [a: 1, b: 2]
     assert emoji_env[:groups] == [a: 1, b: 2]
     assets_env = Application.get_env(:pleroma, :assets)
     assert assets_env[:mascots] == [a: 1, b: 2]
-
-    on_exit(fn ->
-      Application.put_env(:pleroma, :emoji, emoji)
-      Application.put_env(:pleroma, :assets, assets)
-    end)
   end
 
   describe "pleroma restart" do
   end
 
   describe "pleroma restart" do
@@ -114,8 +121,7 @@ defmodule Pleroma.Config.TransferTaskTest do
     end
 
     test "don't restart if no reboot time settings were changed" do
     end
 
     test "don't restart if no reboot time settings were changed" do
-      emoji = Application.get_env(:pleroma, :emoji)
-      on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
+      clear_config(:emoji)
 
       ConfigDB.create(%{
         group: ":pleroma",
 
       ConfigDB.create(%{
         group: ":pleroma",
@@ -130,8 +136,7 @@ defmodule Pleroma.Config.TransferTaskTest do
     end
 
     test "on reboot time key" do
     end
 
     test "on reboot time key" do
-      chat = Application.get_env(:pleroma, :chat)
-      on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
+      clear_config(:chat)
 
       ConfigDB.create(%{
         group: ":pleroma",
 
       ConfigDB.create(%{
         group: ":pleroma",
@@ -143,8 +148,7 @@ defmodule Pleroma.Config.TransferTaskTest do
     end
 
     test "on reboot time subkey" do
     end
 
     test "on reboot time subkey" do
-      captcha = Application.get_env(:pleroma, Pleroma.Captcha)
-      on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
+      clear_config(Pleroma.Captcha)
 
       ConfigDB.create(%{
         group: ":pleroma",
 
       ConfigDB.create(%{
         group: ":pleroma",
@@ -156,13 +160,8 @@ defmodule Pleroma.Config.TransferTaskTest do
     end
 
     test "don't restart pleroma on reboot time key and subkey if there is false flag" do
     end
 
     test "don't restart pleroma on reboot time key and subkey if there is false flag" do
-      chat = Application.get_env(:pleroma, :chat)
-      captcha = Application.get_env(:pleroma, Pleroma.Captcha)
-
-      on_exit(fn ->
-        Application.put_env(:pleroma, :chat, chat)
-        Application.put_env(:pleroma, Pleroma.Captcha, captcha)
-      end)
+      clear_config(:chat)
+      clear_config(Pleroma.Captcha)
 
       ConfigDB.create(%{
         group: ":pleroma",
 
       ConfigDB.create(%{
         group: ":pleroma",