WardrikTesting
A Wardrik.Server for testing packages built on
Wardrik's protocol, without Wardrik itself.
Packages under the hub, such as a channel or an HTTP surface, can't depend on the hub, even in tests. They test against this server instead. The hub's own suite tests them together, end to end.
Install
def deps do
[
{:wardrik_testing, "~> 0.1.0-rc.1", only: :test}
]
end
Usage
Start the server under a name unique to the test, and act through a scope on it:
setup context do
name = :"server #{context.test}"
:ok =
WardrikTesting.Server.start(name,
secrets: ["wrk_good"],
offered: [{"acme/triage", ["chat"]}]
)
scope =
Wardrik.Scope.new(WardrikTesting.Server, name, "acme/@maria",
roles: [:owner],
resources: ["*"]
)
%{scope: scope}
end
test "asks the agent", %{scope: scope} do
{:ok, _message} = Wardrik.Agent.ask(scope, "acme/triage/t1", "Hi")
assert_received {:asked, "acme/triage/t1", "Hi", "acme/@maria"}
end
Give an HTTP surface or a channel the server as {WardrikTesting.Server, name}, the same way the
hub passes itself.
What the test receives
| Message | Sent for |
|---|---|
{:ran, id, input} |
each operation |
{:streamed, id, input} |
each stream |
{:asked, conversation, text, principal_id} |
each message |
{:offered, worker, tools} |
each worker's tools |
How it answers
- Most operations return the protocol's own example output.
- The
:offeredagents are listed and defined. acme/missingis never found.
To have messages answered in the conversation's log, start WardrikEvents under
WardrikTesting.Server.events(name). Then:
echowaits on the callcall_1.failfails.- Anything else is answered
"Answered: "followed by the message.
See WardrikTesting.Script.