Versioning

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

02-functionality.sql (2753B)


      1 BEGIN;
      2     -- load pgtap - change next line to point to correct path for your system!
      3     \i t/00-load.sql.inc
      4 
      5     SELECT plan(13);
      6 
      7     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.' );
      8 
      9     SELECT lives_ok(
     10         $$SELECT _v.register_patch( 'first_patch' )$$,
     11         'Installation of patch without dependencies AND conflicts.'
     12     );
     13 
     14     SELECT results_eq(
     15         'SELECT patch_name COLLATE "C", applied_tsz, applied_by COLLATE "C", requires, conflicts  FROM _v.patches',
     16         $$SELECT 'first_patch'::text COLLATE "C" as patch_name, now() as applied_tsz, current_user::TEXT COLLATE "C" as applied_by, '{}'::TEXT[] as requires, '{}'::TEXT[] as conflicts$$,
     17         'Sanity check if patch is correctly saved.'
     18     );
     19 
     20     SELECT lives_ok(
     21         $$SELECT _v.assert_patch_is_applied( 'first_patch' )$$,
     22         'Assert first patch is applied.'
     23     );
     24 
     25     SELECT throws_ok(
     26         $$SELECT _v.assert_patch_is_applied( 'bogus_patch' )$$,
     27         'P0001',
     28         'Patch bogus_patch is not applied!',
     29         'Raise exception when asserting a patch has been applied when it has not.'
     30     );
     31 
     32     SELECT lives_ok(
     33         $$SELECT _v.register_patch( 'second_patch', ARRAY[ 'first_patch' ], NULL )$$,
     34         'Installation of patch with dependencies.'
     35     );
     36     SELECT lives_ok(
     37         $$SELECT _v.register_patch( 'third_patch', ARRAY[ 'first_patch', 'second_patch' ], ARRAY[ 'bad_patch' ] )$$,
     38         'Installation of patch with dependencies and conflict.'
     39     );
     40     SELECT throws_matching(
     41         $$SELECT _v.register_patch( 'fourth_patch', ARRAY[ 'bad_patch' ], ARRAY[ 'another' ] )$$,
     42         'Missing prerequisite',
     43         'Installation of patch without meeting its requirements.'
     44     );
     45     SELECT throws_matching(
     46         $$SELECT _v.register_patch( 'fifth_patch', NULL, ARRAY[ 'first_patch' ] )$$,
     47         'Versioning patches conflict.',
     48         'Installation of patch with conflicting patch installed'
     49     );
     50     SELECT throws_matching(
     51         $$SELECT _v.register_patch( 'first_patch' )$$,
     52         'already applied',
     53         'Installation of patch that is already installed.'
     54     );
     55     SELECT throws_matching(
     56         $$SELECT _v.unregister_patch( 'first_patch' )$$,
     57         'it is required',
     58         'De-installation of patch that is required BY something ELSE.'
     59     );
     60     SELECT throws_matching(
     61         $$SELECT _v.unregister_patch( 'bad_patch' )$$,
     62         'is not installed',
     63         'De-installation of patch that is not installed'
     64     );
     65     SELECT lives_ok(
     66         $$SELECT _v.unregister_patch( 'third_patch' )$$,
     67         'De-Installation of patch.'
     68     );
     69 
     70     SELECT * FROM finish();
     71 
     72 ROLLBACK;
     73