IF Commons GitHub

sql/extensions/assertions/assert

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0049-sql-assertions FR-001, 0049-sql-assertions FR-002, 0049-sql-assertions FR-003, 0049-sql-assertions FR-005

Assertions about a database (commons data 0049-sql-assertions): what must be true of its structure and its rows, written once as values and run in three ways: inside PostgreSQL as pgTAP, inside any of the dialects as one query that returns TAP lines (no extension), and from TypeScript through a driver. The structural assertions are made from the state a schema has (snapshotOf), so that a table, a column, a key or an index that a database lacks or has changed is a failing test with the name of what is wrong.

Source: commons/data/sql/extensions/assertions/assert.ts

8 of 9 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Assertiontype
type Assertion = | { readonly kind: "has-table"; readonly table: Named } | { readonly kind: "has-view"; readonly vie… (651 characters)
type Assertion =
  | { readonly kind: "has-table"; readonly table: Named }
  | { readonly kind: "has-view"; readonly view: Named }
  | { readonly kind: "has-column"; readonly table: Named; readonly column: string; readonly notNull?: boolean }
  | { readonly kind: "has-primary-key"; readonly table: Named; readonly columns: readonly string[] }
  | { readonly kind: "has-index"; readonly table: Named; readonly index: string }
  | { readonly kind: "rows"; readonly description: string; readonly query: string; readonly expected: readonly (readonly Literal[])[] }
  | { readonly kind: "fails"; readonly description: string; readonly statement: string };

One thing held to be true of a database.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

describeAssertionfunction
function describeAssertion(a: Assertion): string

What an assertion says of itself, as the description of its line.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

failsconst
const fails: (description: string, statement: string) => Assertion

A test that a statement fails: a constraint that holds refuses it.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Namedinterfaceno test imports it
interface Named

A table or view by the name it has in the database.

MemberTypeWhat it is
namestring
schema?string
pgTapScriptfunction
function pgTapScript(assertions: readonly Assertion[], d: Dialect): string

The assertions as a pgTAP script, for a PostgreSQL where the pgtap extension is installed: a plan, a test for each assertion, and finish().

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

rowsconst
const rows: (description: string, query: string, expected: readonly (readonly Literal[])[]) => Assertion

A test that a query gives exactly the rows expected, in any order.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

runAssertionsfunction
function runAssertions(assertions: readonly Assertion[], driver: Driver, d: Dialect): Promise<readonly TapNode[]>

Runs assertions from TypeScript through a driver, and gives their results as TAP nodes: the structural ones and the rows by the same SQL as tapQuery, and a statement that must fail by running it (in a transaction that is rolled back, so that a statement that is not refused changes nothing).

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

structuralTestsfunction
function structuralTests(state: State, d: Dialect): readonly Assertion[]

The tests that every table, column, primary key and index of a state exists as the state says; a view is added by hand. A column the database numbers is held to exist, and its nullability is not asserted.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

tapQueryfunction
function tapQuery(assertions: readonly Assertion[], d: Dialect): string

One query that gives a TAP line for each assertion, in order, in the column tap: SQL any dialect runs, with no extension. An assertion that a statement fails cannot be made by a query, so its line says it was skipped; runAssertions and pgTAP do run it.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.