Skip to main content

Atlas Testing

test migrate

The test "migrate" "name" block describes a migrate test case.

test "migrate" "20240613061102" {
migrate {
to = "20240613061046"
}
exec {
sql = "INSERT INTO users (name) VALUES ('Ada Lovelace')"
}
migrate {
to = "20240613061102"
}
exec {
sql = "SELECT first_name,last_name FROM users"
output = "Ada, Lovelace"
}
}

test.migrate attributes

NameRequiredValue
skipfalsebool

test.migrate blocks

test.assert

The assert block executes an SQL statement and expects a single-row, single-column result with a true value.

test.assert attributes
NameRequiredValue
error_messagefalsestring
sqltruestring
test.assert constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.catch

The catch block executes one or more SQL statements and expects an error to occur.

test.catch attributes
NameRequiredValue
errorfalsestring
sqltruestring
test.catch constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.cleanup

The cleanup block registers a command to be called when the test case is completed.

cleanup {
sql = "SELECT pg_catalog.set_config('search_path', '', false)"
}
test.cleanup attributes
NameRequiredValue
sqltruestring
test.cleanup constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.exec

The exec block executes one or more SQL statements and expects all of them to succeed. If output or match is defined, the output of the SQL statement is compared to the expected value.

test.exec attributes
NameRequiredValue
formatfalse

enum (csv, table)

matchfalsestring
outputfalsestring
sqltruestring
test.exec constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[output, match]

test.external

The external allows executing external programs to insert data or run assertions on the dev-database used by test case.

external {
program = [
"go", "run", "seed.go",
"--dev-url", testing.dev_url,
]
}
test.external attributes
NameRequiredValue
matchfalsestring
outputfalsestring
programtrue

List of strings

working_dirfalsestring
test.external constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[output, match]

test.log

The log block logs a message to the test output.

test.log attributes
NameRequiredValue
messagetruestring
test.log constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.migrate

test.migrate attributes
NameRequiredValue
totruestring
test.migrate constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test plan

The test "plan" "name" block describes a schema plan test case.

test "plan" "20240613061102" {
schema {
url = "atlas://repo?version=20240613061046"
}
exec {
sql = "INSERT INTO users (name) VALUES ('Ada Lovelace')"
}
apply {
url = "file://name.plan.hcl"
}
exec {
sql = "SELECT first_name,last_name FROM users"
output = "Ada, Lovelace"
}
}

test.plan attributes

NameRequiredValue
skipfalsebool

test.plan blocks

test.apply

test.apply attributes
NameRequiredValue
urltruestring
test.apply constraints
ConstraintValue
Requiredtrue
Require Namefalse

test.assert

The assert block executes an SQL statement and expects a single-row, single-column result with a true value.

test.assert attributes
NameRequiredValue
error_messagefalsestring
sqltruestring
test.assert constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.catch

The catch block executes one or more SQL statements and expects an error to occur.

test.catch attributes
NameRequiredValue
errorfalsestring
sqltruestring
test.catch constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.cleanup

The cleanup block registers a command to be called when the test case is completed.

cleanup {
sql = "SELECT pg_catalog.set_config('search_path', '', false)"
}
test.cleanup attributes
NameRequiredValue
sqltruestring
test.cleanup constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.exec

The exec block executes one or more SQL statements and expects all of them to succeed. If output or match is defined, the output of the SQL statement is compared to the expected value.

test.exec attributes
NameRequiredValue
formatfalse

enum (csv, table)

matchfalsestring
outputfalsestring
sqltruestring
test.exec constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[output, match]

test.external

The external allows executing external programs to insert data or run assertions on the dev-database used by test case.

external {
program = [
"go", "run", "seed.go",
"--dev-url", testing.dev_url,
]
}
test.external attributes
NameRequiredValue
matchfalsestring
outputfalsestring
programtrue

List of strings

working_dirfalsestring
test.external constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[output, match]

test.log

The log block logs a message to the test output.

test.log attributes
NameRequiredValue
messagetruestring
test.log constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.schema

test.schema attributes
NameRequiredValue
urltruestring
test.schema constraints
ConstraintValue
Requiredtrue
Require Namefalse

test schema

The test "schema" "name" block describes a schema test case.

test "schema" "postal" {
parallel = true
exec {
sql = "SELECT '12345'::us_postal_code"
}
catch {
sql = "SELECT 'hello'::us_postal_code"
}
}

test.schema attributes

NameRequiredValue
parallelfalsebool
skipfalsebool

test.schema blocks

test.assert

The assert block executes an SQL statement and expects a single-row, single-column result with a true value.

test.assert attributes
NameRequiredValue
error_messagefalsestring
sqltruestring
test.assert constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.catch

The catch block executes one or more SQL statements and expects an error to occur.

test.catch attributes
NameRequiredValue
errorfalsestring
sqltruestring
test.catch constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.cleanup

The cleanup block registers a command to be called when the test case is completed.

cleanup {
sql = "SELECT pg_catalog.set_config('search_path', '', false)"
}
test.cleanup attributes
NameRequiredValue
sqltruestring
test.cleanup constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

test.exec

The exec block executes one or more SQL statements and expects all of them to succeed. If output or match is defined, the output of the SQL statement is compared to the expected value.

test.exec attributes
NameRequiredValue
formatfalse

enum (csv, table)

matchfalsestring
outputfalsestring
sqltruestring
test.exec constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[output, match]

test.external

The external allows executing external programs to insert data or run assertions on the dev-database used by test case.

external {
program = [
"go", "run", "seed.go",
"--dev-url", testing.dev_url,
]
}
test.external attributes
NameRequiredValue
matchfalsestring
outputfalsestring
programtrue

List of strings

working_dirfalsestring
test.external constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[output, match]

test.log

The log block logs a message to the test output.

test.log attributes
NameRequiredValue
messagetruestring
test.log constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue