Alternera.Plugin.Test.Contract (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

The contract of Alternera.Plugin as ExUnit tests, for a plugin's own suite. plugin_contract/2 writes a describe block of tests over the predicates of Alternera.Plugin.Test, so a plugin in another Mix project is checked the way the proxy checks its built-in ones:

defmodule MyPlugin.ContractTest do
  use ExUnit.Case, async: true
  use Alternera.Plugin.Test.Contract

  plugin_contract MyPlugin,
    settings: [%{"direction" => "response", "fields" => []}]
end

settings lists settings the plugin needs to mean anything, besides the bare ones every plugin is tried with (%{}, and each direction for a directional plugin); every one init/1 accepts is run in each phase its signature needs. stream_bodies adds bodies a streaming step is fed to check that a skip sends the body as it came.

source_contract/2 does the same for a message source (Alternera.Plugin.Provisional.Source):

source_contract MyPlugin.Source,
  plugin: MyPlugin,
  settings: [%{"queue_url" => "https://queue.example/q"}],
  broker: :broker

# Arranges the broker (a stub, a queue) for `state` and answers the
# settings to open the source with and the context's overrides.
def broker(:messages), do: ...  # at least one message waits
def broker(:empty), do: ...     # none waits
def broker(:failing), do: ...   # the next receive fails

settings lists settings source_init/1 accepts. Without broker the tests that open the source are left out.

Summary

Functions

The contract tests for plugin; settings: adds settings to try, stream_bodies: bodies.

The contract tests for the message source source: settings: (settings it accepts, at least one), plugin: (the plugin whose source/0 names it), broker: (the name of a public function of the test module that arranges the broker, see the moduledoc).

Functions

plugin_contract(plugin, opts \\ [])

(macro)

The contract tests for plugin; settings: adds settings to try, stream_bodies: bodies.

source_contract(source, opts)

(macro)

The contract tests for the message source source: settings: (settings it accepts, at least one), plugin: (the plugin whose source/0 names it), broker: (the name of a public function of the test module that arranges the broker, see the moduledoc).