summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-05-26 14:21:24 -0400
committerMark Felder <feld@feld.me>2024-05-26 14:21:24 -0400
commit03f4b461895802259c895c81462a3e9d0d31c1e5 (patch)
treeefd8896a80d98fc8b77b3dc4204b55646633d98b /test
parentf2b0d5f1d02e243a7a1a6f339b59e5abcb8e1bd8 (diff)
downloadpleroma-03f4b461895802259c895c81462a3e9d0d31c1e5.tar.gz
pleroma-03f4b461895802259c895c81462a3e9d0d31c1e5.zip
Test that healthchecks behave correctly for the expected HTTP responses
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/search/healthcheck_test.exs49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/pleroma/search/healthcheck_test.exs b/test/pleroma/search/healthcheck_test.exs
new file mode 100644
index 000000000..e7649d949
--- /dev/null
+++ b/test/pleroma/search/healthcheck_test.exs
@@ -0,0 +1,49 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Search.HealthcheckTest do
+ use Pleroma.DataCase
+
+ import Tesla.Mock
+
+ alias Pleroma.Search.Healthcheck
+
+ @good1 "http://good1.example.com/healthz"
+ @good2 "http://good2.example.com/health"
+ @bad "http://bad.example.com/healthy"
+
+ setup do
+ mock(fn
+ %{method: :get, url: @good1} ->
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }
+
+ %{method: :get, url: @good2} ->
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }
+
+ %{method: :get, url: @bad} ->
+ %Tesla.Env{
+ status: 503,
+ body: ""
+ }
+ end)
+
+ :ok
+ end
+
+ test "true for 200 responses" do
+ assert Healthcheck.check([@good1])
+ assert Healthcheck.check([@good1, @good2])
+ end
+
+ test "false if any response is not a 200" do
+ refute Healthcheck.check([@bad])
+ refute Healthcheck.check([@good1, @bad])
+ end
+end