Mediate.Conformance.RepoCase (mediate_conformance v0.1.0)

Copy Markdown View Source

The conformance case for a repo. use Mediate.Conformance.RepoCase, repo: MyApp.Repo writes the tests that hold the repo to the seam. The repo must answer __mediate__/1. It must export nothing outside the surface of the build it comes from. It must refuse, before any SQL, every query, write, and raw call on a protected schema that carries no decision and no exemption.

The test starts the repo. The protected schema's table need not exist.

defmodule MyApp.RepoTest do
  use Mediate.Conformance.RepoCase, repo: MyApp.Repo
end

An adopter that names a Mediate.Conformance.RepoCase.Rows module as well gets five more tests, one per guarantee in guarantees/0. Those five write to the database the rows module names.

defmodule MyApp.RepoTest do
  use Mediate.Conformance.RepoCase, repo: MyApp.Repo, rows: MyApp.RepoRows
end

Summary

Functions

E3: a write the seam never saw publishes nothing, and the write reaches the row.

E2: every bulk call the repo exports raises on an audited schema, and none of them publishes.

Runs the assertion of one guarantee, by its id, against the repo and the rows module.

E4: the handler's own write is in the transaction the write opened, so a rollback takes it too.

E1: one event for the insert, one for the update, with the fact fields the update changed.

E5: a get under a decision is one access event that names the row, the decision, and the subject. An exists? is one that names no row. A read under an exemption is none.

Calls the function with fixture arguments on the protected schema and expects the refusal.

Fails unless the repo answers __mediate__/1 and exports only classified functions.

The guarantee table under "The guarantees" in the conformance document as data, one id and one sentence per row. The freeze test in mediate holds it to the document row for row.

The rows module's own setup, where it defines one.

The query, write, and raw functions the repo exports, each swept with fixture arguments.

Functions

assert_around_silent(repo, rows)

@spec assert_around_silent(module(), module()) :: :ok

E3: a write the seam never saw publishes nothing, and the write reaches the row.

assert_bulk_refused(repo, rows)

@spec assert_bulk_refused(module(), module()) :: :ok

E2: every bulk call the repo exports raises on an audited schema, and none of them publishes.

assert_guarantee(binary, repo, rows)

@spec assert_guarantee(String.t(), module(), module()) :: :ok

Runs the assertion of one guarantee, by its id, against the repo and the rows module.

assert_handler_joins(repo, rows)

@spec assert_handler_joins(module(), module()) :: :ok

E4: the handler's own write is in the transaction the write opened, so a rollback takes it too.

assert_one_change(repo, rows)

@spec assert_one_change(module(), module()) :: :ok

E1: one event for the insert, one for the update, with the fact fields the update changed.

assert_read_evented(repo, rows)

@spec assert_read_evented(module(), module()) :: :ok

E5: a get under a decision is one access event that names the row, the decision, and the subject. An exists? is one that names no row. A read under an exemption is none.

assert_refused(repo, arg)

@spec assert_refused(module(), {atom(), non_neg_integer()}) :: :ok

Calls the function with fixture arguments on the protected schema and expects the refusal.

assert_surface(repo)

@spec assert_surface(module()) :: :ok

Fails unless the repo answers __mediate__/1 and exports only classified functions.

guarantees()

@spec guarantees() :: [{String.t(), String.t()}]

The guarantee table under "The guarantees" in the conformance document as data, one id and one sentence per row. The freeze test in mediate holds it to the document row for row.

setup_rows(rows, tags)

@spec setup_rows(module(), map()) :: :ok

The rows module's own setup, where it defines one.

swept(repo)

@spec swept(module()) :: [{atom(), non_neg_integer()}]

The query, write, and raw functions the repo exports, each swept with fixture arguments.