Skip to content

Commit

Permalink
Add 2 more col_is_pk() variants without description
Browse files Browse the repository at this point in the history
Thanks to Matteo Ferrando for the PR; resolves #199.
  • Loading branch information
theory committed May 21, 2022
1 parent d63d6a8 commit 8f4a881
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 49 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Revision history for pgTAP
format, which will not affect tests run by `pg_prove`, but will break tests
that depend on diffing files, as `pg_regress` does. Thanks to Matt DeLuco for
highlighting the visual confusion of the indented diagnostic (#264).
* Added variants of `col_is_pk()` with schema and without description (variants
without schema or description already existed). Thanks to Matteo Ferrando for
the PR (#199)!

1.2.0 2021-12-05T18:08:13Z
--------------------------
Expand Down
2 changes: 2 additions & 0 deletions doc/pgtap.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -4707,6 +4707,8 @@ foreign key does *not* exist.

SELECT col_is_pk( :schema, :table, :columns, :description );
SELECT col_is_pk( :schema, :table, :column, :description );
SELECT col_is_pk( :schema, :table, :columns );
SELECT col_is_pk( :schema, :table, :column );
SELECT col_is_pk( :table, :columns, :description );
SELECT col_is_pk( :table, :column, :description );
SELECT col_is_pk( :table, :columns );
Expand Down
12 changes: 12 additions & 0 deletions sql/pgtap--1.2.0--1.2.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,15 @@ BEGIN
RETURN;
END;
$$ LANGUAGE plpgsql;

-- col_is_pk( schema, table, column[] )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[] )
RETURNS TEXT AS $$
SELECT col_is_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a primary key' );
$$ LANGUAGE sql;

-- col_is_pk( schema, table, column )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT col_is_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a primary key' );
$$ LANGUAGE sql;
16 changes: 14 additions & 2 deletions sql/pgtap.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -1983,13 +1983,19 @@ RETURNS NAME[] AS $$
SELECT * FROM _keys($1, $2) LIMIT 1;
$$ LANGUAGE sql;

-- col_is_pk( schema, table, column, description )
-- col_is_pk( schema, table, column[], description )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT is( _ckeys( $1, $2, 'p' ), $3, $4 );
$$ LANGUAGE sql;

-- col_is_pk( table, column, description )
-- col_is_pk( schema, table, column[] )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[] )
RETURNS TEXT AS $$
SELECT col_is_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a primary key' );
$$ LANGUAGE sql;

-- col_is_pk( table, column[], description )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT is( _ckeys( $1, 'p' ), $2, $3 );
Expand All @@ -2007,6 +2013,12 @@ RETURNS TEXT AS $$
SELECT col_is_pk( $1, $2, ARRAY[$3], $4 );
$$ LANGUAGE sql;

-- col_is_pk( schema, table, column )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT col_is_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a primary key' );
$$ LANGUAGE sql;

-- col_is_pk( table, column, description )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
Expand Down
98 changes: 52 additions & 46 deletions test/expected/pktap.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\unset ECHO
1..84
1..90
ok 1 - has_pk( schema, table, description ) should pass
ok 2 - has_pk( schema, table, description ) should have the proper description
ok 3 - has_pk( schema, table, description ) should have the proper diagnostics
Expand Down Expand Up @@ -39,48 +39,54 @@ ok 36 - hasnt_pk( table, description ) pass should have the proper diagnostics
ok 37 - col_is_pk( schema, table, column, description ) should pass
ok 38 - col_is_pk( schema, table, column, description ) should have the proper description
ok 39 - col_is_pk( schema, table, column, description ) should have the proper diagnostics
ok 40 - col_is_pk( table, column, description ) should pass
ok 41 - col_is_pk( table, column, description ) should have the proper description
ok 42 - col_is_pk( table, column, description ) should have the proper diagnostics
ok 43 - col_is_pk( table, column ) should pass
ok 44 - col_is_pk( table, column ) should have the proper description
ok 45 - col_is_pk( table, column ) should have the proper diagnostics
ok 46 - col_is_pk( schema, table, column, description ) fail should fail
ok 47 - col_is_pk( schema, table, column, description ) fail should have the proper description
ok 48 - col_is_pk( schema, table, column, description ) fail should have the proper diagnostics
ok 49 - col_is_pk( table, column, description ) fail should fail
ok 50 - col_is_pk( table, column, description ) fail should have the proper description
ok 51 - col_is_pk( table, column, description ) fail should have the proper diagnostics
ok 52 - col_is_pk( schema, table, column[], description ) should pass
ok 53 - col_is_pk( schema, table, column[], description ) should have the proper description
ok 54 - col_is_pk( schema, table, column[], description ) should have the proper diagnostics
ok 55 - col_is_pk( table, column[], description ) should pass
ok 56 - col_is_pk( table, column[], description ) should have the proper description
ok 57 - col_is_pk( table, column[], description ) should have the proper diagnostics
ok 58 - col_is_pk( table, column[] ) should pass
ok 59 - col_is_pk( table, column[] ) should have the proper description
ok 60 - col_is_pk( table, column[] ) should have the proper diagnostics
ok 61 - col_isnt_pk( schema, table, column, description ) should fail
ok 62 - col_isnt_pk( schema, table, column, description ) should have the proper description
ok 63 - col_isnt_pk( schema, table, column, description ) should have the proper diagnostics
ok 64 - col_isnt_pk( table, column, description ) should fail
ok 65 - col_isnt_pk( table, column, description ) should have the proper description
ok 66 - col_isnt_pk( table, column, description ) should have the proper diagnostics
ok 67 - col_isnt_pk( table, column ) should fail
ok 68 - col_isnt_pk( table, column ) should have the proper description
ok 69 - col_isnt_pk( table, column ) should have the proper diagnostics
ok 70 - col_isnt_pk( schema, table, column, description ) pass should pass
ok 71 - col_isnt_pk( schema, table, column, description ) pass should have the proper description
ok 72 - col_isnt_pk( schema, table, column, description ) pass should have the proper diagnostics
ok 73 - col_isnt_pk( table, column, description ) pass should pass
ok 74 - col_isnt_pk( table, column, description ) pass should have the proper description
ok 75 - col_isnt_pk( table, column, description ) pass should have the proper diagnostics
ok 76 - col_isnt_pk( schema, table, column[], description ) should pass
ok 77 - col_isnt_pk( schema, table, column[], description ) should have the proper description
ok 78 - col_isnt_pk( schema, table, column[], description ) should have the proper diagnostics
ok 79 - col_isnt_pk( table, column[], description ) should pass
ok 80 - col_isnt_pk( table, column[], description ) should have the proper description
ok 81 - col_isnt_pk( table, column[], description ) should have the proper diagnostics
ok 82 - col_isnt_pk( table, column[] ) should pass
ok 83 - col_isnt_pk( table, column[] ) should have the proper description
ok 84 - col_isnt_pk( table, column[] ) should have the proper diagnostics
ok 40 - col_is_pk( schema, table, column ) should pass
ok 41 - col_is_pk( schema, table, column ) should have the proper description
ok 42 - col_is_pk( schema, table, column ) should have the proper diagnostics
ok 43 - col_is_pk( table, column, description ) should pass
ok 44 - col_is_pk( table, column, description ) should have the proper description
ok 45 - col_is_pk( table, column, description ) should have the proper diagnostics
ok 46 - col_is_pk( table, column ) should pass
ok 47 - col_is_pk( table, column ) should have the proper description
ok 48 - col_is_pk( table, column ) should have the proper diagnostics
ok 49 - col_is_pk( schema, table, column, description ) fail should fail
ok 50 - col_is_pk( schema, table, column, description ) fail should have the proper description
ok 51 - col_is_pk( schema, table, column, description ) fail should have the proper diagnostics
ok 52 - col_is_pk( table, column, description ) fail should fail
ok 53 - col_is_pk( table, column, description ) fail should have the proper description
ok 54 - col_is_pk( table, column, description ) fail should have the proper diagnostics
ok 55 - col_is_pk( schema, table, column[], description ) should pass
ok 56 - col_is_pk( schema, table, column[], description ) should have the proper description
ok 57 - col_is_pk( schema, table, column[], description ) should have the proper diagnostics
ok 58 - col_is_pk( schema, table, column[] ) should pass
ok 59 - col_is_pk( schema, table, column[] ) should have the proper description
ok 60 - col_is_pk( schema, table, column[] ) should have the proper diagnostics
ok 61 - col_is_pk( table, column[], description ) should pass
ok 62 - col_is_pk( table, column[], description ) should have the proper description
ok 63 - col_is_pk( table, column[], description ) should have the proper diagnostics
ok 64 - col_is_pk( table, column[] ) should pass
ok 65 - col_is_pk( table, column[] ) should have the proper description
ok 66 - col_is_pk( table, column[] ) should have the proper diagnostics
ok 67 - col_isnt_pk( schema, table, column, description ) should fail
ok 68 - col_isnt_pk( schema, table, column, description ) should have the proper description
ok 69 - col_isnt_pk( schema, table, column, description ) should have the proper diagnostics
ok 70 - col_isnt_pk( table, column, description ) should fail
ok 71 - col_isnt_pk( table, column, description ) should have the proper description
ok 72 - col_isnt_pk( table, column, description ) should have the proper diagnostics
ok 73 - col_isnt_pk( table, column ) should fail
ok 74 - col_isnt_pk( table, column ) should have the proper description
ok 75 - col_isnt_pk( table, column ) should have the proper diagnostics
ok 76 - col_isnt_pk( schema, table, column, description ) pass should pass
ok 77 - col_isnt_pk( schema, table, column, description ) pass should have the proper description
ok 78 - col_isnt_pk( schema, table, column, description ) pass should have the proper diagnostics
ok 79 - col_isnt_pk( table, column, description ) pass should pass
ok 80 - col_isnt_pk( table, column, description ) pass should have the proper description
ok 81 - col_isnt_pk( table, column, description ) pass should have the proper diagnostics
ok 82 - col_isnt_pk( schema, table, column[], description ) should pass
ok 83 - col_isnt_pk( schema, table, column[], description ) should have the proper description
ok 84 - col_isnt_pk( schema, table, column[], description ) should have the proper diagnostics
ok 85 - col_isnt_pk( table, column[], description ) should pass
ok 86 - col_isnt_pk( table, column[], description ) should have the proper description
ok 87 - col_isnt_pk( table, column[], description ) should have the proper diagnostics
ok 88 - col_isnt_pk( table, column[] ) should pass
ok 89 - col_isnt_pk( table, column[] ) should have the proper description
ok 90 - col_isnt_pk( table, column[] ) should have the proper diagnostics
18 changes: 17 additions & 1 deletion test/sql/pktap.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\unset ECHO
\i test/setup.sql

SELECT plan(84);
SELECT plan(90);
--SELECT * FROM no_plan();

-- This will be rolled back. :-)
Expand Down Expand Up @@ -139,6 +139,14 @@ SELECT * FROM check_test(
''
);

SELECT * FROM check_test(
col_is_pk( 'public', 'sometab', 'id'::name ),
true,
'col_is_pk( schema, table, column )',
'Column public.sometab(id) should be a primary key',
''
);

SELECT * FROM check_test(
col_is_pk( 'sometab', 'id', 'sometab.id should be a pk' ),
true,
Expand Down Expand Up @@ -192,6 +200,14 @@ SELECT * FROM check_test(
''
);

SELECT * FROM check_test(
col_is_pk( 'public', 'argh', ARRAY['id', 'name']::name[] ),
true,
'col_is_pk( schema, table, column[] )',
'Columns public.argh(id, name) should be a primary key',
''
);

SELECT * FROM check_test(
col_is_pk( 'argh', ARRAY['id', 'name'], 'id + name should be a pk' ),
true,
Expand Down

0 comments on commit 8f4a881

Please sign in to comment.