diff options
| author | rinpatch <rinpatch@sdf.org> | 2020-02-05 16:59:21 +0000 | 
|---|---|---|
| committer | rinpatch <rinpatch@sdf.org> | 2020-02-05 16:59:21 +0000 | 
| commit | 49e80a15377fe460d7ac644601609700fffea632 (patch) | |
| tree | af98f0e28eb063c48152658294a4dce0d05131d4 /test | |
| parent | a56db789359c7c7d57b45e6c68f791eeadc171e4 (diff) | |
| parent | 33bd8fbffea79b8ca510a098ad4654b8f01324d6 (diff) | |
| download | pleroma-49e80a15377fe460d7ac644601609700fffea632.tar.gz pleroma-49e80a15377fe460d7ac644601609700fffea632.zip | |
Merge branch 'feature/restart-pleroma-from-outside-application' into 'develop'
Restarting pleroma from outside application
See merge request pleroma/pleroma!2144
Diffstat (limited to 'test')
| -rw-r--r-- | test/config/transfer_task_test.exs | 73 | ||||
| -rw-r--r-- | test/web/admin_api/admin_api_controller_test.exs | 43 | 
2 files changed, 114 insertions, 2 deletions
| diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs index 53e8703fd..ebdc951cf 100644 --- a/test/config/transfer_task_test.exs +++ b/test/config/transfer_task_test.exs @@ -5,6 +5,8 @@  defmodule Pleroma.Config.TransferTaskTest do    use Pleroma.DataCase +  import ExUnit.CaptureLog +    alias Pleroma.Config.TransferTask    alias Pleroma.ConfigDB @@ -105,4 +107,75 @@ defmodule Pleroma.Config.TransferTaskTest do        Application.put_env(:pleroma, :assets, assets)      end)    end + +  describe "pleroma restart" do +    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) + +      ConfigDB.create(%{ +        group: ":pleroma", +        key: ":emoji", +        value: [groups: [a: 1, b: 2]] +      }) + +      refute String.contains?( +               capture_log(fn -> TransferTask.start_link([]) end), +               "pleroma restarted" +             ) +    end + +    test "restart pleroma on reboot time key" do +      chat = Application.get_env(:pleroma, :chat) +      on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end) + +      ConfigDB.create(%{ +        group: ":pleroma", +        key: ":chat", +        value: [enabled: false] +      }) + +      assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted" +    end + +    test "restart pleroma on reboot time subkey" do +      captcha = Application.get_env(:pleroma, Pleroma.Captcha) +      on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end) + +      ConfigDB.create(%{ +        group: ":pleroma", +        key: "Pleroma.Captcha", +        value: [seconds_valid: 60] +      }) + +      assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted" +    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) + +      ConfigDB.create(%{ +        group: ":pleroma", +        key: ":chat", +        value: [enabled: false] +      }) + +      ConfigDB.create(%{ +        group: ":pleroma", +        key: "Pleroma.Captcha", +        value: [seconds_valid: 60] +      }) + +      refute String.contains?( +               capture_log(fn -> TransferTask.load_and_update_env([], false) end), +               "pleroma restarted" +             ) +    end +  end  end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 5c767219a..81e346fb8 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -2043,7 +2043,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do          Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)          Application.put_env(:pleroma, :http, http)          Application.put_env(:tesla, :adapter, Tesla.Mock) -        :ok = File.rm("config/test.exported_from_db.secret.exs")        end)      end @@ -2170,7 +2169,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do        assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}      end -    test "save config setting without key", %{conn: conn} do +    test "save configs setting without explicit key", %{conn: conn} do        level = Application.get_env(:quack, :level)        meta = Application.get_env(:quack, :meta)        webhook_url = Application.get_env(:quack, :webhook_url) @@ -2256,6 +2255,34 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do               }      end +    test "saving config which need pleroma reboot", %{conn: conn} do +      chat = Pleroma.Config.get(:chat) +      on_exit(fn -> Pleroma.Config.put(:chat, chat) end) + +      conn = +        post( +          conn, +          "/api/pleroma/admin/config", +          %{ +            configs: [ +              %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]} +            ] +          } +        ) + +      assert json_response(conn, 200) == %{ +               "configs" => [ +                 %{ +                   "db" => [":enabled"], +                   "group" => ":pleroma", +                   "key" => ":chat", +                   "value" => [%{"tuple" => [":enabled", true]}] +                 } +               ], +               "need_reboot" => true +             } +    end +      test "saving config with nested merge", %{conn: conn} do        config =          insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: [k1: 1, k2: 2])) @@ -3001,6 +3028,18 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end    end +  describe "GET /api/pleroma/admin/restart" do +    clear_config(:configurable_from_database) do +      Pleroma.Config.put(:configurable_from_database, true) +    end + +    test "pleroma restarts", %{conn: conn} do +      ExUnit.CaptureLog.capture_log(fn -> +        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{} +      end) =~ "pleroma restarted" +    end +  end +    describe "GET /api/pleroma/admin/users/:nickname/statuses" do      setup do        user = insert(:user) | 
