Mediate.Test.Fake (mediate v0.1.0)

Copy Markdown View Source

The adapter Tier 1 runs first and the seam's tests bind. Its rules are a table in an Agent, one per test. A test binds it through the configuration override as {Mediate.Test.Fake, rules: pid}. An entry allows one holder one operation on one object or on any object of a type. A holder is one subject, an account whatever its kind, or any subject. The fake allows nothing else.

Without a table the fake answers with the verdict option, which is :deny unless the test says otherwise.

It returns a value of the real type everywhere the real adapters do. scope returns a real dynamic. A table told to fail/2 answers every call with the reason :engine_unreachable, so the port's fail-closed path runs against it.

Summary

Types

A holder, an operation, and an object reference whose id can be :any.

Who an entry allows: one subject, an account whatever kind asks, or anyone.

Functions

Allow the holder to perform operation on the object reference, whose id can be :any.

The answer the fake gives with no table bound.

The entries, sorted.

Make every call fail with the detail. nil makes the calls answer again.

Empty the table and clear any failure.

Starts an empty rule table, unnamed.

Types

entry()

@type entry() :: {holder(), atom(), {atom(), Mediate.Id.t() | term() | :any}}

A holder, an operation, and an object reference whose id can be :any.

holder()

@type holder() :: Mediate.subject() | Mediate.Id.t() | :any

Who an entry allows: one subject, an account whatever kind asks, or anyone.

Functions

allow(rules, subject, operation, object)

@spec allow(pid(), holder(), atom(), {atom(), term()}) :: :ok

Allow the holder to perform operation on the object reference, whose id can be :any.

answer(options)

@spec answer(keyword()) :: Mediate.Answer.t()

The answer the fake gives with no table bound.

entries(rules)

@spec entries(pid()) :: [entry()]

The entries, sorted.

fail(rules, detail)

@spec fail(pid(), String.t() | nil) :: :ok

Make every call fail with the detail. nil makes the calls answer again.

reset(rules)

@spec reset(pid()) :: :ok

Empty the table and clear any failure.

revoke(rules, subject, operation, object)

@spec revoke(pid(), holder(), atom(), {atom(), term()}) :: :ok

Remove one entry.

start_link()

@spec start_link() :: Agent.on_start()

Starts an empty rule table, unnamed.