Skip to content

Commit

Permalink
Add domains_are() and enums_are().
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Nov 20, 2009
1 parent 2edd599 commit af27dbf
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -23,7 +23,7 @@ Revision history for pgTAP
* Added `throws_like()`, `throws_ilike()`, `throws_matching()`, and
`throws_imatching()` to test that an SQL statement throws an error message
matching a `LIKE` pattern or a regular expression.
* Added `roles_are()` and `types_are()`.
* Added `roles_are()`, `types_are()`, `domains_are()`, and `enums_are()`.

0.22 2009-07-31T00:26:16
-------------------------
Expand Down
65 changes: 58 additions & 7 deletions README.pgtap
Expand Up @@ -1592,8 +1592,9 @@ missing rules, like so:
);

Tests that all of the types in the named schema are the only types in that
schema. If the `:schema` argument is omitted, the types must be visible in the
search path, excluding `pg_catalog` and `information_schema`. If the
schema, including base types, composite types, domains, enums, and
pseudo-types. If the `:schema` argument is omitted, the types must be visible
in the search path, excluding `pg_catalog` and `information_schema`. If the
description is omitted, a generally useful default description will be
generated.

Expand All @@ -1606,6 +1607,58 @@ missing types, like so:
# Missing types:
# timezone

### `domains_are( schema, domains[], description )` ###
### `domains_are( schema, domains[] )` ###
### `domains_are( domains[], description )` ###
### `domains_are( domains[] )` ###

SELECT domains_are(
'myschema',
ARRAY[ 'timezone', 'state' ],
'Should have the correct domains in myschema'
);

Tests that all of the domains in the named schema are the only domains in that
schema. If the `:schema` argument is omitted, the domains must be visible in
the search path, excluding `pg_catalog` and `information_schema`. If the
description is omitted, a generally useful default description will be
generated.

In the event of a failure, you'll see diagnostics listing the extra and/or
missing domains, like so:

# Failed test 327: "Schema someschema should have the correct domains"
# Extra domains:
# somedomain
# Missing domains:
# timezone

### `enums_are( schema, enums[], description )` ###
### `enums_are( schema, enums[] )` ###
### `enums_are( enums[], description )` ###
### `enums_are( enums[] )` ###

SELECT enums_are(
'myschema',
ARRAY[ 'timezone', 'state' ],
'Should have the correct enums in myschema'
);

Tests that all of the enums in the named schema are the only enums in that
schema. Enums are supported in PostgreSQL 8.3 and up. If the `:schema`
argument is omitted, the enums must be visible in the search path, excluding
`pg_catalog` and `information_schema`. If the description is omitted, a
generally useful default description will be generated.

In the event of a failure, you'll see diagnostics listing the extra and/or
missing enums, like so:

# Failed test 333: "Schema someschema should have the correct enums"
# Extra enums:
# someenum
# Missing enums:
# bug_status

To Have or Have Not
-------------------

Expand Down Expand Up @@ -3951,9 +4004,9 @@ No changes. Everything should just work.
------------
* A patch is applied that removes the `enum_has_labels()` function, and
`col_has_default()` cannot be used to test for columns specified with
`DEFAULT NULL` (even though that's the implied default default). Also, a
number of assignments casts are added to increase compatibility. The casts
are:
`DEFAULT NULL` (even though that's the implied default default). The
`has_enums()` function won't work. Also, a number of assignments casts are
added to increase compatibility. The casts are:
+ `boolean` to `text`
+ `text[]` to `text`
+ `name[]` to `text`
Expand Down Expand Up @@ -3985,8 +4038,6 @@ To Do
+ `sequence_increments_by()`
+ `sequence_starts_at()`
+ `sequence_cycles()`
+ `domains_are()`
+ `enums_are()`
+ `triggers_are()`
+ `casts_are()`
+ `operators_are()`
Expand Down
26 changes: 25 additions & 1 deletion expected/aretap.out
@@ -1,5 +1,5 @@
\unset ECHO
1..306
1..330
ok 1 - tablespaces_are(schemas, desc) should pass
ok 2 - tablespaces_are(schemas, desc) should have the proper description
ok 3 - tablespaces_are(schemas, desc) should have the proper diagnostics
Expand Down Expand Up @@ -306,3 +306,27 @@ ok 303 - types_are(types, desc) + extra should have the proper diagnostics
ok 304 - types_are(types, desc) + extra & missing should fail
ok 305 - types_are(types, desc) + extra & missing should have the proper description
ok 306 - types_are(types, desc) + extra & missing should have the proper diagnostics
ok 307 - domains_are(schema, domains, desc) should pass
ok 308 - domains_are(schema, domains, desc) should have the proper description
ok 309 - domains_are(schema, domains, desc) should have the proper diagnostics
ok 310 - domains_are(schema, domains) should pass
ok 311 - domains_are(schema, domains) should have the proper description
ok 312 - domains_are(schema, domains) should have the proper diagnostics
ok 313 - domains_are(schema, domains, desc) fail should fail
ok 314 - domains_are(schema, domains, desc) fail should have the proper description
ok 315 - domains_are(schema, domains, desc) fail should have the proper diagnostics
ok 316 - domains_are(schema, domains) fail should fail
ok 317 - domains_are(schema, domains) fail should have the proper description
ok 318 - domains_are(schema, domains) fail should have the proper diagnostics
ok 319 - domains_are(domains, desc) should pass
ok 320 - domains_are(domains, desc) should have the proper description
ok 321 - domains_are(domains, desc) should have the proper diagnostics
ok 322 - domains_are(domains) should pass
ok 323 - domains_are(domains) should have the proper description
ok 324 - domains_are(domains) should have the proper diagnostics
ok 325 - domains_are(domains, desc) fail should fail
ok 326 - domains_are(domains, desc) fail should have the proper description
ok 327 - domains_are(domains, desc) fail should have the proper diagnostics
ok 328 - domains_are(domains) fail should fail
ok 329 - domains_are(domains) fail should have the proper description
ok 330 - domains_are(domains) fail should have the proper diagnostics
26 changes: 25 additions & 1 deletion expected/enumtap.out
@@ -1,5 +1,5 @@
\unset ECHO
1..72
1..96
ok 1 - has_type(enum) should pass
ok 2 - has_type(enum) should have the proper description
ok 3 - has_type(enum) should have the proper diagnostics
Expand Down Expand Up @@ -72,3 +72,27 @@ ok 69 - enum_has_labels(schema, enum, labels, desc) fail should have the proper
ok 70 - enum_has_labels(enum, labels, desc) fail should fail
ok 71 - enum_has_labels(enum, labels, desc) fail should have the proper description
ok 72 - enum_has_labels(enum, labels, desc) fail should have the proper diagnostics
ok 73 - enums_are(schema, enums, desc) should pass
ok 74 - enums_are(schema, enums, desc) should have the proper description
ok 75 - enums_are(schema, enums, desc) should have the proper diagnostics
ok 76 - enums_are(schema, enums) should pass
ok 77 - enums_are(schema, enums) should have the proper description
ok 78 - enums_are(schema, enums) should have the proper diagnostics
ok 79 - enums_are(schema, enums, desc) fail should fail
ok 80 - enums_are(schema, enums, desc) fail should have the proper description
ok 81 - enums_are(schema, enums, desc) fail should have the proper diagnostics
ok 82 - enums_are(schema, enums) fail should fail
ok 83 - enums_are(schema, enums) fail should have the proper description
ok 84 - enums_are(schema, enums) fail should have the proper diagnostics
ok 85 - enums_are(enums, desc) should pass
ok 86 - enums_are(enums, desc) should have the proper description
ok 87 - enums_are(enums, desc) should have the proper diagnostics
ok 88 - enums_are(enums) should pass
ok 89 - enums_are(enums) should have the proper description
ok 90 - enums_are(enums) should have the proper diagnostics
ok 91 - enums_are(enums, desc) fail should fail
ok 92 - enums_are(enums, desc) fail should have the proper description
ok 93 - enums_are(enums, desc) fail should have the proper diagnostics
ok 94 - enums_are(enums) fail should fail
ok 95 - enums_are(enums) fail should have the proper description
ok 96 - enums_are(enums) fail should have the proper diagnostics
74 changes: 69 additions & 5 deletions pgtap.sql.in
Expand Up @@ -6587,8 +6587,7 @@ RETURNS TEXT AS $$
SELECT roles_are( $1, 'There should be the correct roles' );
$$ LANGUAGE SQL;

-- types_are( schema, types[], description )
CREATE OR REPLACE FUNCTION types_are ( NAME, NAME[], TEXT )
CREATE OR REPLACE FUNCTION _types_are ( NAME, NAME[], TEXT, CHAR[] )
RETURNS TEXT AS $$
SELECT _are(
'types',
Expand All @@ -6602,6 +6601,7 @@ RETURNS TEXT AS $$
)
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND n.nspname = $1
AND t.typtype = ANY( COALESCE($4, ARRAY['b', 'c', 'd', 'p', 'e']) )
EXCEPT
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
Expand All @@ -6619,19 +6619,26 @@ RETURNS TEXT AS $$
)
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND n.nspname = $1
AND t.typtype = ANY( COALESCE($4, ARRAY['b', 'c', 'd', 'p', 'e']) )
),
$3
);
$$ LANGUAGE SQL;

-- types_are( schema, types[], description )
CREATE OR REPLACE FUNCTION types_are ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, $3, NULL );
$$ LANGUAGE SQL;

-- types_are( schema, types[] )
CREATE OR REPLACE FUNCTION types_are ( NAME, NAME[] )
RETURNS TEXT AS $$
SELECT types_are( $1, $2, 'Schema ' || quote_ident($1) || ' should have the correct types' );
SELECT _types_are( $1, $2, 'Schema ' || quote_ident($1) || ' should have the correct types', NULL );
$$ LANGUAGE SQL;

-- types_are( types[], description )
CREATE OR REPLACE FUNCTION types_are ( NAME[], TEXT )
CREATE OR REPLACE FUNCTION _types_are ( NAME[], TEXT, CHAR[] )
RETURNS TEXT AS $$
SELECT _are(
'types',
Expand All @@ -6646,6 +6653,7 @@ RETURNS TEXT AS $$
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND n.nspname NOT IN('pg_catalog', 'information_schema')
AND pg_catalog.pg_type_is_visible(t.oid)
AND t.typtype = ANY( COALESCE($3, ARRAY['b', 'c', 'd', 'p', 'e']) )
EXCEPT
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
Expand All @@ -6664,14 +6672,70 @@ RETURNS TEXT AS $$
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND n.nspname NOT IN('pg_catalog', 'information_schema')
AND pg_catalog.pg_type_is_visible(t.oid)
AND t.typtype = ANY( COALESCE($3, ARRAY['b', 'c', 'd', 'p', 'e']) )
),
$2
);
$$ LANGUAGE SQL;


-- types_are( types[], description )
CREATE OR REPLACE FUNCTION types_are ( NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, NULL );
$$ LANGUAGE SQL;

-- types_are( types[] )
CREATE OR REPLACE FUNCTION types_are ( NAME[] )
RETURNS TEXT AS $$
SELECT types_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct types' );
SELECT _types_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct types', NULL );
$$ LANGUAGE SQL;

-- domains_are( schema, domains[], description )
CREATE OR REPLACE FUNCTION domains_are ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, $3, ARRAY['d'] );
$$ LANGUAGE SQL;

-- domains_are( schema, domains[] )
CREATE OR REPLACE FUNCTION domains_are ( NAME, NAME[] )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, 'Schema ' || quote_ident($1) || ' should have the correct domains', ARRAY['d'] );
$$ LANGUAGE SQL;

-- domains_are( domains[], description )
CREATE OR REPLACE FUNCTION domains_are ( NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, ARRAY['d'] );
$$ LANGUAGE SQL;

-- domains_are( domains[] )
CREATE OR REPLACE FUNCTION domains_are ( NAME[] )
RETURNS TEXT AS $$
SELECT _types_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct domains', ARRAY['d'] );
$$ LANGUAGE SQL;

-- enums_are( schema, enums[], description )
CREATE OR REPLACE FUNCTION enums_are ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, $3, ARRAY['e'] );
$$ LANGUAGE SQL;

-- enums_are( schema, enums[] )
CREATE OR REPLACE FUNCTION enums_are ( NAME, NAME[] )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, 'Schema ' || quote_ident($1) || ' should have the correct enums', ARRAY['e'] );
$$ LANGUAGE SQL;

-- enums_are( enums[], description )
CREATE OR REPLACE FUNCTION enums_are ( NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _types_are( $1, $2, ARRAY['e'] );
$$ LANGUAGE SQL;

-- enums_are( enums[] )
CREATE OR REPLACE FUNCTION enums_are ( NAME[] )
RETURNS TEXT AS $$
SELECT _types_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct enums', ARRAY['e'] );
$$ LANGUAGE SQL;

0 comments on commit af27dbf

Please sign in to comment.