test: add supertest plugin management method

This commit is contained in:
2026-05-08 22:34:41 +02:00
parent 926e59f579
commit 131524f3bf
3 changed files with 46 additions and 0 deletions
+13
View File
@@ -127,6 +127,19 @@ defmodule Supertest.API do
def received_cluster_pubsub(_params), do: {:error, :invalid_run_id}
def management_echo(context, params) do
{:ok,
%{
ok: true,
plugin: context.plugin,
method: context.method,
version: context.version,
admin: context.admin?,
actor_pubkey: context.actor_pubkey,
params: params
}}
end
defp destroy_all(entries, fun) do
Enum.reduce_while(entries, :ok, fn entry, :ok ->
case fun.(entry) do
+10
View File
@@ -28,6 +28,16 @@ defmodule Tribes.Plugins.Supertest.Plugin do
api_routes: [
{"/", SupertestWeb.APIPlug}
],
management_methods: [
%{
name: "supertest.echo",
version: "1",
module: Supertest.API,
action: :management_echo,
auth: :admin,
description: "Echo plugin management context"
}
],
children: cluster_pubsub_children(context)
})
end
+23
View File
@@ -109,6 +109,29 @@ defmodule Supertest.APITest do
Supertest.API.received_cluster_pubsub(%{"run_id" => run_id})
end
test "echoes plugin management context" do
context = %Tribes.Plugin.ManagementContext{
plugin: "supertest",
method: "supertest.echo",
version: "1",
actor_pubkey: String.duplicate("a", 64),
admin?: true
}
assert {:ok,
%{
ok: true,
plugin: "supertest",
method: "supertest.echo",
version: "1",
admin: true,
actor_pubkey: actor_pubkey,
params: %{"probe" => true}
}} = Supertest.API.management_echo(context, %{"probe" => true})
assert actor_pubkey == String.duplicate("a", 64)
end
defp eventually(assertion, attempts \\ 20)
defp eventually(assertion, attempts) when attempts > 0 do