diff options
author | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-01-18 12:25:56 +0300 |
---|---|---|
committer | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-01-18 12:25:56 +0300 |
commit | e69986169095796f2845c4f859234d96f91bf9ff (patch) | |
tree | ee64255b674c622c7ef3545263c2784f69c7f585 /test/config | |
parent | 89e93fb33f6295428dd84a50c9ca44e26bd169c3 (diff) | |
download | pleroma-e69986169095796f2845c4f859234d96f91bf9ff.tar.gz |
full update for some subkeys
Diffstat (limited to 'test/config')
-rw-r--r-- | test/config/config_db_test.exs | 34 | ||||
-rw-r--r-- | test/config/transfer_task_test.exs | 36 |
2 files changed, 67 insertions, 3 deletions
diff --git a/test/config/config_db_test.exs b/test/config/config_db_test.exs index 7668bc547..19619620e 100644 --- a/test/config/config_db_test.exs +++ b/test/config/config_db_test.exs @@ -155,6 +155,40 @@ defmodule Pleroma.ConfigDBTest do assert ConfigDB.from_binary(updated.value) == Tesla.Adapter.Httpc end + + test "only full update for some subkeys" do + config1 = + insert(:config, + key: ":emoji", + value: ConfigDB.to_binary(groups: [a: 1, b: 2], key: [a: 1]) + ) + + config2 = + insert(:config, + key: ":assets", + value: ConfigDB.to_binary(mascots: [a: 1, b: 2], key: [a: 1]) + ) + + {:ok, _config} = + ConfigDB.update_or_create(%{ + group: config1.group, + key: config1.key, + value: [groups: [c: 3, d: 4], key: [b: 2]] + }) + + {:ok, _config} = + ConfigDB.update_or_create(%{ + group: config2.group, + key: config2.key, + value: [mascots: [c: 3, d: 4], key: [b: 2]] + }) + + updated1 = ConfigDB.get_by_params(%{group: config1.group, key: config1.key}) + updated2 = ConfigDB.get_by_params(%{group: config2.group, key: config2.key}) + + assert ConfigDB.from_binary(updated1.value) == [groups: [c: 3, d: 4], key: [a: 1, b: 2]] + assert ConfigDB.from_binary(updated2.value) == [mascots: [c: 3, d: 4], key: [a: 1, b: 2]] + end end test "delete/1" do diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs index 37bea20a3..20dc06863 100644 --- a/test/config/transfer_task_test.exs +++ b/test/config/transfer_task_test.exs @@ -5,6 +5,7 @@ defmodule Pleroma.Config.TransferTaskTest do use Pleroma.DataCase + alias Pleroma.Config.TransferTask alias Pleroma.ConfigDB clear_config(:configurable_from_database) do @@ -34,7 +35,7 @@ defmodule Pleroma.Config.TransferTaskTest do value: [:test_value1, :test_value2] }) - Pleroma.Config.TransferTask.start_link([]) + 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] @@ -63,7 +64,7 @@ defmodule Pleroma.Config.TransferTaskTest do value: [:none] }) - Pleroma.Config.TransferTask.start_link([]) + TransferTask.start_link([]) assert Application.get_env(:quack, :level) == :info assert Application.get_env(:quack, :meta) == [:none] @@ -76,6 +77,35 @@ defmodule Pleroma.Config.TransferTaskTest do end) end + test "transfer config values with full subkey update" do + emoji = Application.get_env(:pleroma, :emoji) + assets = Application.get_env(:pleroma, :assets) + + ConfigDB.create(%{ + group: ":pleroma", + key: ":emoji", + value: [groups: [a: 1, b: 2]] + }) + + ConfigDB.create(%{ + group: ":pleroma", + key: ":assets", + value: [mascots: [a: 1, b: 2]] + }) + + TransferTask.start_link([]) + + emoji_env = Application.get_env(:pleroma, :emoji) + 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 + test "non existing atom" do ConfigDB.create(%{ group: ":pleroma", @@ -84,7 +114,7 @@ defmodule Pleroma.Config.TransferTaskTest do }) assert ExUnit.CaptureLog.capture_log(fn -> - Pleroma.Config.TransferTask.start_link([]) + TransferTask.start_link([]) end) =~ "updating env causes error, group: \":pleroma\", key: \":undefined_atom_key\", value: [live: 2, com: 3], error: %ArgumentError{message: \"argument error\"}" end |