summaryrefslogtreecommitdiff
path: root/test/web/twitter_api/util_controller_test.exs
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-07-20 22:04:47 +0300
committerrinpatch <rinpatch@sdf.org>2019-07-20 22:04:47 +0300
commit196cad46f35a63c18d58cd5d982bc4e1f9b0d7c3 (patch)
tree51fa0436998541c3bcc1885eaa2188d7dbb7d469 /test/web/twitter_api/util_controller_test.exs
parentc3ecaea64dd377b586e3b2a5316e90884ec78fe6 (diff)
parentfe548f322e834c7c81678a460c54c71f1198021c (diff)
downloadpleroma-196cad46f35a63c18d58cd5d982bc4e1f9b0d7c3.tar.gz
pleroma-196cad46f35a63c18d58cd5d982bc4e1f9b0d7c3.zip
Resolve merge conflicts
Diffstat (limited to 'test/web/twitter_api/util_controller_test.exs')
-rw-r--r--test/web/twitter_api/util_controller_test.exs64
1 files changed, 61 insertions, 3 deletions
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 21324399f..3d699e1df 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ import Mock
setup do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -231,10 +232,67 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- test "GET /api/pleroma/healthcheck", %{conn: conn} do
- conn = get(conn, "/api/pleroma/healthcheck")
+ describe "GET /api/pleroma/healthcheck" do
+ setup do
+ config_healthcheck = Pleroma.Config.get([:instance, :healthcheck])
- assert conn.status in [200, 503]
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :healthcheck], config_healthcheck)
+ end)
+
+ :ok
+ end
+
+ test "returns 503 when healthcheck disabled", %{conn: conn} do
+ Pleroma.Config.put([:instance, :healthcheck], false)
+
+ response =
+ conn
+ |> get("/api/pleroma/healthcheck")
+ |> json_response(503)
+
+ assert response == %{}
+ end
+
+ test "returns 200 when healthcheck enabled and all ok", %{conn: conn} do
+ Pleroma.Config.put([:instance, :healthcheck], true)
+
+ with_mock Pleroma.Healthcheck,
+ system_info: fn -> %Pleroma.Healthcheck{healthy: true} end do
+ response =
+ conn
+ |> get("/api/pleroma/healthcheck")
+ |> json_response(200)
+
+ assert %{
+ "active" => _,
+ "healthy" => true,
+ "idle" => _,
+ "memory_used" => _,
+ "pool_size" => _
+ } = response
+ end
+ end
+
+ test "returns 503 when healthcheck enabled and health is false", %{conn: conn} do
+ Pleroma.Config.put([:instance, :healthcheck], true)
+
+ with_mock Pleroma.Healthcheck,
+ system_info: fn -> %Pleroma.Healthcheck{healthy: false} end do
+ response =
+ conn
+ |> get("/api/pleroma/healthcheck")
+ |> json_response(503)
+
+ assert %{
+ "active" => _,
+ "healthy" => false,
+ "idle" => _,
+ "memory_used" => _,
+ "pool_size" => _
+ } = response
+ end
+ end
end
describe "POST /api/pleroma/disable_account" do