You've already forked tribes-plugin-supertest
forked from tribes/tribes-plugin-template
test: add supertest plugin management method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user