Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.8KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Config.TransferTaskTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Config.TransferTask
  7. alias Pleroma.ConfigDB
  8. clear_config(:configurable_from_database) do
  9. Pleroma.Config.put(:configurable_from_database, true)
  10. end
  11. test "transfer config values from db to env" do
  12. refute Application.get_env(:pleroma, :test_key)
  13. refute Application.get_env(:idna, :test_key)
  14. refute Application.get_env(:quack, :test_key)
  15. ConfigDB.create(%{
  16. group: ":pleroma",
  17. key: ":test_key",
  18. value: [live: 2, com: 3]
  19. })
  20. ConfigDB.create(%{
  21. group: ":idna",
  22. key: ":test_key",
  23. value: [live: 15, com: 35]
  24. })
  25. ConfigDB.create(%{
  26. group: ":quack",
  27. key: ":test_key",
  28. value: [:test_value1, :test_value2]
  29. })
  30. TransferTask.start_link([])
  31. assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
  32. assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
  33. assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
  34. on_exit(fn ->
  35. Application.delete_env(:pleroma, :test_key)
  36. Application.delete_env(:idna, :test_key)
  37. Application.delete_env(:quack, :test_key)
  38. end)
  39. end
  40. test "transfer config values for 1 group and some keys" do
  41. level = Application.get_env(:quack, :level)
  42. meta = Application.get_env(:quack, :meta)
  43. ConfigDB.create(%{
  44. group: ":quack",
  45. key: ":level",
  46. value: :info
  47. })
  48. ConfigDB.create(%{
  49. group: ":quack",
  50. key: ":meta",
  51. value: [:none]
  52. })
  53. TransferTask.start_link([])
  54. assert Application.get_env(:quack, :level) == :info
  55. assert Application.get_env(:quack, :meta) == [:none]
  56. default = Pleroma.Config.Holder.config(:quack, :webhook_url)
  57. assert Application.get_env(:quack, :webhook_url) == default
  58. on_exit(fn ->
  59. Application.put_env(:quack, :level, level)
  60. Application.put_env(:quack, :meta, meta)
  61. end)
  62. end
  63. test "transfer config values with full subkey update" do
  64. emoji = Application.get_env(:pleroma, :emoji)
  65. assets = Application.get_env(:pleroma, :assets)
  66. ConfigDB.create(%{
  67. group: ":pleroma",
  68. key: ":emoji",
  69. value: [groups: [a: 1, b: 2]]
  70. })
  71. ConfigDB.create(%{
  72. group: ":pleroma",
  73. key: ":assets",
  74. value: [mascots: [a: 1, b: 2]]
  75. })
  76. TransferTask.start_link([])
  77. emoji_env = Application.get_env(:pleroma, :emoji)
  78. assert emoji_env[:groups] == [a: 1, b: 2]
  79. assets_env = Application.get_env(:pleroma, :assets)
  80. assert assets_env[:mascots] == [a: 1, b: 2]
  81. on_exit(fn ->
  82. Application.put_env(:pleroma, :emoji, emoji)
  83. Application.put_env(:pleroma, :assets, assets)
  84. end)
  85. end
  86. end