Emmanuel BENOîT
e50775ec76
* The main loader script has been updated to generate the list of files it needs to load automatically. As a consequence, files that contained manually-maintained lists of scripts have been removed, and definition directories have been renamed accordingly. * PostgreSQL extension loading and configuration has been moved to a separate script to be loaded automatically in the main transaction. * Data and function definition scripts that had the -data or -functions suffix have been renamed (the suffix is unnecessary). * Unit tests have been reorganised to follow the definition's structure. * Documentation has been improved
90 lines
No EOL
4.3 KiB
PL/PgSQL
90 lines
No EOL
4.3 KiB
PL/PgSQL
/*
|
|
* Test the defs.uoc_resource() functions
|
|
*/
|
|
BEGIN;
|
|
|
|
/* We need a few strings to be used when creating resource definitions, and a natural resource. */
|
|
\i utils/strings.sql
|
|
\i utils/resources.sql
|
|
SELECT _create_test_strings( 7 );
|
|
SELECT _create_natural_resources( 1 , 'natRes' );
|
|
|
|
/****** TESTS BEGIN HERE ******/
|
|
SELECT plan( 22 );
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL name (no category)' );
|
|
SELECT is( defs.uoc_resource( NULL , 'test2' , 1 ) , NULL );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL description (no category)' );
|
|
SELECT is( defs.uoc_resource( 'test1' , NULL , 1 ) , NULL );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL weight (no category)' );
|
|
SELECT is( defs.uoc_resource( 'test1' , 'test2' , NULL ) , NULL );
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL name (with category)' );
|
|
SELECT is( defs.uoc_resource( NULL , 'test2' , 'test3' , 1 ) , NULL );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL description (with category)' );
|
|
SELECT is( defs.uoc_resource( 'test1' , NULL , 'test3' , 1 ) , NULL );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL category' );
|
|
SELECT is( defs.uoc_resource( 'test1' , 'test2' , NULL , 1 ) , NULL );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - NULL weight (with category)' );
|
|
SELECT is( defs.uoc_resource( 'test1' , 'test2' , 'test3' , NULL ) , NULL );
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - creation without category' );
|
|
SELECT is( defs.uoc_resource( 'test3' , 'test4' , 1 ) , 'CREATED' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - creation results without category' );
|
|
SELECT results_eq(
|
|
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
|
FROM defs.resources
|
|
WHERE resource_name_id = _get_string( 'test3' )
|
|
AND resource_category_id IS NULL $$ ,
|
|
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , 1 ) $$
|
|
);
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - creation with category' );
|
|
SELECT is( defs.uoc_resource( 'test5' , 'test6' , 'test7' , 1 ) , 'CREATED' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - creation results with category' );
|
|
SELECT results_eq(
|
|
$$ SELECT * FROM defs.resources
|
|
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
|
$$ VALUES ( _get_string( 'test5' ) , _get_string( 'test6' ) , _get_string( 'test7' ) , 1 ) $$
|
|
);
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - update without category' );
|
|
SELECT is( defs.uoc_resource( 'test3' , 'test7', 2 ) , 'UPDATED' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - update results without category' );
|
|
SELECT results_eq(
|
|
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
|
FROM defs.resources
|
|
WHERE resource_name_id = _get_string( 'test3' )
|
|
AND resource_category_id IS NULL $$ ,
|
|
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test7' ) , 2 ) $$
|
|
);
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - update with category' );
|
|
SELECT is( defs.uoc_resource( 'test3' , 'test4' , 'test7' , 1 ) , 'UPDATED' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - update results with category' );
|
|
SELECT results_eq(
|
|
$$ SELECT * FROM defs.resources
|
|
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
|
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , _get_string( 'test7' ) , 1 ) $$
|
|
);
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - incorrect name string' );
|
|
SELECT is( defs.uoc_resource( 'does-not-exist' , 'test2' , 1 ) , 'BAD_STRINGS' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - incorrect description string' );
|
|
SELECT is( defs.uoc_resource( 'test1' , 'does-not-exist' , 1 ) , 'BAD_STRINGS' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - incorrect category string' );
|
|
SELECT is( defs.uoc_resource( 'test1' , 'test2' , 'does-not-exist' , 1 ) , 'BAD_STRINGS' );
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - duplicate description on new resource' );
|
|
SELECT is( defs.uoc_resource( 'test1' , 'test4' , 1 ) , 'DUP_DESCR' );
|
|
SELECT diag_test_name( 'defs.uoc_resource() - duplicate description on existing resource' );
|
|
SELECT is( defs.uoc_resource( 'test5' , 'test4' , 1 ) , 'DUP_DESCR' );
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - update on natural resource' );
|
|
SELECT is( defs.uoc_resource( 'natRes1' , 'test2' , 1 ) , 'BAD_TYPE' );
|
|
|
|
SELECT diag_test_name( 'defs.uoc_resource() - weight <= 0' );
|
|
SELECT is( defs.uoc_resource( 'natRes1' , 'test2' , 0 ) , 'BAD_VALUE' );
|
|
|
|
SELECT * FROM finish( );
|
|
ROLLBACK; |