Versioning

Fork/mirror of https://gitlab.com/depesz/Versioning
git clone https://ccx.te2000.cz/git/Versioning
Log | Files | Refs | README | LICENSE

commit 2dbcdf94e93a68a6f273375408a92d42c69dd5a5
parent 86bcac9fa93079fe8b264a28530712bdb09d685f
Author: Hubert depesz Lubaczewski <depesz@depesz.com>
Date:   Thu, 10 May 2018 15:11:44 +0200

Merge pull request #5 from bradmacpherson/master

Add function to assert that a patch has been applied
Diffstat:
Minstall.versioning.sql | 13+++++++++++++
Mt/02-functionality.sql | 14+++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/install.versioning.sql b/install.versioning.sql @@ -94,6 +94,19 @@ END; $$ language plpgsql; COMMENT ON FUNCTION _v.unregister_patch( TEXT ) IS 'Function to unregister patches in database. Dies if the patch is not registered, or if unregistering it would break dependencies.'; +CREATE OR REPLACE FUNCTION _v.assert_patch_is_applied( IN in_patch_name TEXT ) RETURNS TEXT as $$ +DECLARE + t_text TEXT; +BEGIN + SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name; + IF NOT FOUND THEN + RAISE EXCEPTION 'Patch % is not applied!', in_patch_name; + END IF; + RETURN format('Patch %s is applied.', in_patch_name); +END; +$$ language plpgsql; +COMMENT ON FUNCTION _v.assert_patch_is_applied( TEXT ) IS 'Function that can be used to make sure that patch has been applied.'; + CREATE OR REPLACE FUNCTION _v.assert_user_is_superuser() RETURNS TEXT as $$ DECLARE v_super bool; diff --git a/t/02-functionality.sql b/t/02-functionality.sql @@ -2,7 +2,7 @@ BEGIN; -- load pgtap - change next line to point to correct path for your system! \i t/00-load.sql.inc - SELECT plan(11); + SELECT plan(13); SELECT is( ( SELECT count(*) FROM _v.patches ), 0::bigint, 'When running tests _v.patches table should be empty to prevent bad interactions between patches and tests.' ); @@ -18,6 +18,18 @@ BEGIN; ); SELECT lives_ok( + $$SELECT _v.assert_patch_is_applied( 'first_patch' )$$, + 'Assert first patch is applied.' + ); + + SELECT throws_ok( + $$SELECT _v.assert_patch_is_applied( 'bogus_patch' )$$, + 'P0001', + 'Patch bogus_patch is not applied!', + 'Raise exception when asserting a patch has been applied when it has not.' + ); + + SELECT lives_ok( $$SELECT _v.register_patch( 'second_patch', ARRAY[ 'first_patch' ], NULL )$$, 'Installation of patch with dependencies.' );