allow disabling prometheus entirely
[akkoma] / test / pleroma / web / akkoma_api / metrics_controller_test.exs
1 defmodule Pleroma.Web.AkkomaAPI.MetricsControllerTest do
2 use Pleroma.Web.ConnCase, async: true
3
4 describe "GET /api/v1/akkoma/metrics" do
5 test "should return metrics when the user has admin:metrics" do
6 %{conn: conn} = oauth_access(["admin:metrics"])
7 resp = conn
8 |> get("/api/v1/akkoma/metrics")
9 |> text_response(200)
10
11 assert resp =~ "# HELP"
12 end
13
14 test "should not allow users that do not have the admin:metrics scope" do
15 %{conn: conn} = oauth_access(["read:metrics"])
16 conn
17 |> get("/api/v1/akkoma/metrics")
18 |> json_response(403)
19 end
20
21 test "should be disabled by export_prometheus_metrics" do
22 clear_config([:instance, :export_prometheus_metrics], false)
23 %{conn: conn} = oauth_access(["admin:metrics"])
24 conn
25 |> get("/api/v1/akkoma/metrics")
26 |> response(404)
27 end
28 end
29 end