From: Jason Etheridge Date: Mon, 24 Jun 2013 19:36:10 +0000 (-0400) Subject: pgTAP examples X-Git-Tag: sprint4-merge-nov22~2912 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c36c86e4bf1e8be3a613a267e7462ff3c080c45d;p=working%2FEvergreen.git pgTAP examples These specific ones do not assume stock test data such as the concerto bibs, and I think such tests should go elsewhere. You need to install pgTAP. I did the following for my test environment: git clone git://github.com/theory/pgtap.git cd pgtap make make installcheck sudo make install Then in my Evergreen database with psql, I did: CREATE EXTENSION pgtap; I also installed a CPAN module to get pg_prove: sudo cpan TAP::Parser::SourceHandler::pgTAP You can use psql to run a given test like so: opensrf@dev141:~/git/Evergreen/Open-ILS/src/sql/Pg/t (pgtap)$ psql -d evergreen -f 0799.state_field_required_toggle.s 1..4 ok 1 - actor.usr_address.state does not have the NOT NULL constraint ok 2 - ui.patron.edit.au.state.require exists ok 3 - ui.patron.edit.au.state.show exists ok 4 - ui.patron.edit.au.state.suggest exists Or you can use pg_prove on all or some of them: opensrf@dev141:~/git/Evergreen/Open-ILS/src/sql/Pg/t (pgtap)$ pg_prove -d evergreen *.s 0799.state_field_required_toggle.s .. ok dewey.s ............................. 1/6 # Failed (TODO) test 6: "testing prefix plus decimal" # 'YR_DVD_800_100000000000000' # < # 'YR_000000000000000_DVD_900' dewey.s ............................. ok schema.s ............................ ok versions.s .......................... ok All tests successful. Files=4, Tests=39, 0 wallclock secs ( 0.05 usr 0.03 sys + 0.13 cusr 0.07 csys = 0.28 CPU) Result: PASS Signed-off-by: Jason Etheridge Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/sql/Pg/t/0799.state_field_required_toggle.s b/Open-ILS/src/sql/Pg/t/0799.state_field_required_toggle.s new file mode 100644 index 0000000000..88559375d7 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/0799.state_field_required_toggle.s @@ -0,0 +1,47 @@ +\set ECHO +\set QUIET 1 +-- Turn off echo and keep things quiet. + +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager + +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true +\set QUIET 1 + +-- Load the TAP functions. +BEGIN; + +-- Plan the tests. +SELECT plan(4); + +-- Run the tests. + +SELECT col_is_null( + 'actor', + 'usr_address', + 'state', + 'actor.usr_address.state does not have the NOT NULL constraint' +); + +SELECT isnt_empty( + 'SELECT * FROM config.org_unit_setting_type WHERE name = $$ui.patron.edit.au.state.require$$', + 'ui.patron.edit.au.state.require exists' +); + +SELECT isnt_empty( + 'SELECT * FROM config.org_unit_setting_type WHERE name = $$ui.patron.edit.au.state.show$$', + 'ui.patron.edit.au.state.show exists' +); + +SELECT isnt_empty( + 'SELECT * FROM config.org_unit_setting_type WHERE name = $$ui.patron.edit.au.state.suggest$$', + 'ui.patron.edit.au.state.suggest exists' +); + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK; diff --git a/Open-ILS/src/sql/Pg/t/README b/Open-ILS/src/sql/Pg/t/README new file mode 100644 index 0000000000..e40a652d59 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/README @@ -0,0 +1 @@ +For the tests we put here, let's not assume the stock test data is loaded. diff --git a/Open-ILS/src/sql/Pg/t/dewey.s b/Open-ILS/src/sql/Pg/t/dewey.s new file mode 100644 index 0000000000..50f42ba372 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/dewey.s @@ -0,0 +1,67 @@ +\set ECHO +\set QUIET 1 +-- Turn off echo and keep things quiet. + +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager + +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true +\set QUIET 1 + +-- Load the TAP functions. +BEGIN; + +-- Plan the tests. +SELECT plan(6); + +-- Run the tests. Converted from Koha's ClassSortRoutine_Dewey.t + +SELECT is( + asset.label_normalizer_dewey(NULL), + '', + 'testing whitespace' +); + +SELECT is( + asset.label_normalizer_dewey('.... .....'), + '', + 'testing fullstops' +); + +-- I think these tests below may be looking too deeply into the implementation, +-- but including them for now + +SELECT is( + asset.label_normalizer_dewey('123 456'), + '123_456000000000000', + 'testing numbers' +); + +SELECT is( + asset.label_normalizer_dewey('abc123 456'), + 'ABC_123_456000000000000', + 'testing alphanumeric' +); + +SELECT is( + asset.label_normalizer_dewey('ab c123 45 6'), + 'AB_C123_45_600000000000000', + 'testing middle whitespace' +); + +SELECT todo('Desired behavior in contention. See https://bugs.launchpad.net/evergreen/+bug/1150939', 1); + +SELECT cmp_ok( + asset.label_normalizer_dewey('YR DVD 800.1'), + '<', + asset.label_normalizer_dewey('YR DVD 900'), + 'testing prefix plus decimal' +); + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK; diff --git a/Open-ILS/src/sql/Pg/t/schema.s b/Open-ILS/src/sql/Pg/t/schema.s new file mode 100644 index 0000000000..7d4feca854 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/schema.s @@ -0,0 +1,52 @@ +\set ECHO +\set QUIET 1 +-- Turn off echo and keep things quiet. + +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager + +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true +\set QUIET 1 + +-- Load the TAP functions. +BEGIN; + +-- Plan the tests. +SELECT plan(27); + +-- Run the tests. +SELECT has_schema('action','Has action schema'); +SELECT has_schema('action_trigger','Has action_trigger schema'); +SELECT has_schema('actor','Has actor schema'); +SELECT has_schema('acq','Has acq schema'); +SELECT has_schema('asset','Has actor schema'); +SELECT has_schema('auditor','Has auditor schema'); +SELECT has_schema('authority','Has authority schema'); +SELECT has_schema('biblio','Has biblio schema'); +SELECT has_schema('booking','Has booking schema'); +SELECT has_schema('config','Has config schema'); +SELECT has_schema('container','Has container schema'); +SELECT has_schema('evergreen','Has evergreen schema'); +SELECT has_schema('extend_reporter','Has extend_reporter schema'); +SELECT has_schema('metabib','Has metabib schema'); +SELECT has_schema('money','Has money schema'); +SELECT has_schema('offline','Has offline schema'); +SELECT has_schema('permission','Has permission schema'); +SELECT has_schema('public','Has public schema'); +SELECT has_schema('query','Has query schema'); +SELECT has_schema('reporter','Has reporter schema'); +SELECT has_schema('search','Has search schema'); +SELECT has_schema('serial','Has serial schema'); +SELECT has_schema('staging','Has staging schema'); +SELECT has_schema('stats','Has stats schema'); +SELECT has_schema('url_verify','Has url_verify schema'); +SELECT has_schema('vandelay','Has vandelay schema'); +SELECT has_schema('unapi','Has unapi schema'); + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK; diff --git a/Open-ILS/src/sql/Pg/t/versions.s b/Open-ILS/src/sql/Pg/t/versions.s new file mode 100644 index 0000000000..b611cbc868 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/versions.s @@ -0,0 +1,35 @@ +\set ECHO +\set QUIET 1 +-- Turn off echo and keep things quiet. + +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager + +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true +\set QUIET 1 + +-- Load the TAP functions. +BEGIN; + +-- Plan the tests. +SELECT plan(2); + +-- Run the tests. + +SELECT CASE WHEN pg_version_num() >= 90000 + THEN pass('Running PostgreSQL 9+') + ELSE fail('Not running PostgreSQL 9+') +END; + +SELECT isnt_empty( + 'SELECT COUNT(*) FROM config.upgrade_log', + 'Have rows in config.upgrade_log' +); + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK;