/*
 * Test the defs.uoc_resource() functions
 */
BEGIN;
	/* Create a fake internal function that will just push its parameters to
	 * a temporary table.
	 */
	CREATE TEMPORARY TABLE calls_to_internal(
		name TEXT , description TEXT , category TEXT , weight INT 
	) ON COMMIT DROP;
	CREATE OR REPLACE FUNCTION defs.uoc_resource_internal(
				_name TEXT ,
				_description TEXT ,
				_category TEXT ,
				_weight INT )
		RETURNS defs.resource_update_result
		CALLED ON NULL INPUT
		VOLATILE
		SECURITY INVOKER
	AS $$
		INSERT INTO calls_to_internal VALUES (
			$1 , $2 , CASE WHEN $3 IS NULL THEN 'NULL' ELSE $3 END , $4
		);
		SELECT 'BAD_STRINGS'::defs.resource_update_result;
	$$ LANGUAGE SQL;

	/****** TESTS BEGIN HERE ******/
	SELECT plan( 2 );

	SELECT diag_test_name( 'defs.uoc_resource() - Calls internal function (without category)' );
	SELECT defs.uoc_resource( 'a' , 'b' , 1 );
	SELECT set_eq(
		$$ SELECT * FROM calls_to_internal; $$ ,
		$$ VALUES( 'a' , 'b' , 'NULL' , 1 ) $$
	);
	DELETE FROM calls_to_internal;

	SELECT diag_test_name( 'defs.uoc_resource() - Calls internal function (without category)' );
	SELECT defs.uoc_resource( 'a' , 'b' , 'c' , 1 );
	SELECT set_eq(
		$$ SELECT * FROM calls_to_internal; $$ ,
		$$ VALUES( 'a' , 'b' , 'c' , 1 ) $$
	);

	SELECT * FROM finish( );
ROLLBACK;