Commit a108fe18 authored by Brad MacPherson's avatar Brad MacPherson

Add function to assert that a patch has been applied

parent 86bcac9f
......@@ -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 $$
t_text TEXT;
SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
RAISE EXCEPTION 'Patch % is not applied!', in_patch_name;
RETURN format('Patch %s is applied.', in_patch_name);
$$ 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 $$
v_super bool;
......@@ -2,7 +2,7 @@ BEGIN;
-- load pgtap - change next line to point to correct path for your system!
\i t/
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.' );
......@@ -17,6 +17,18 @@ BEGIN;
'Sanity check if patch is correctly saved.'
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' )$$,
'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.'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment