Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add non-description versions of col_is_pk with schema #199

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/pgtap.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -4560,6 +4560,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
2 changes: 2 additions & 0 deletions sql/pgtap--unpackaged--0.91.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ ALTER EXTENSION pgtap ADD FUNCTION _keys ( NAME, CHAR );
ALTER EXTENSION pgtap ADD FUNCTION _ckeys ( NAME, NAME, CHAR );
ALTER EXTENSION pgtap ADD FUNCTION _ckeys ( NAME, CHAR );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME, NAME[] );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME[], TEXT );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME[] );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME, NAME, TEXT );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME, NAME );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME, TEXT );
ALTER EXTENSION pgtap ADD FUNCTION col_is_pk ( NAME, NAME );
ALTER EXTENSION pgtap ADD FUNCTION col_isnt_pk ( NAME, NAME, NAME[], TEXT );
Expand Down
16 changes: 14 additions & 2 deletions sql/pgtap.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -1969,13 +1969,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 @@ -1993,6 +1999,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 @@ -135,6 +135,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 @@ -188,6 +196,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