This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/040-functions/025-resources/020-uoc-resource.sql

46 lines
1.3 KiB
MySQL
Raw Normal View History

/*
* 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;