fix: hemar: include object does not exists
This commit is contained in:
@@ -1547,9 +1547,13 @@ render_template(TemplateNode *node, Jsonb *define, StringInfo result, MemoryCont
|
|||||||
/* Get the include data from the context */
|
/* Get the include data from the context */
|
||||||
JsonbValue *include_data = jsonb_get_by_path_internal(define, include_path, context);
|
JsonbValue *include_data = jsonb_get_by_path_internal(define, include_path, context);
|
||||||
|
|
||||||
elog(DEBUG1, "Include data: %s", JsonbToCString(NULL, &JsonbValueToJsonb(include_data)->root, VARSIZE_ANY_EXHDR(JsonbValueToJsonb(include_data))));
|
if (!include_data)
|
||||||
|
{
|
||||||
|
elog(WARNING, "Include data not found");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (include_data != NULL && include_data->type == jbvBinary)
|
if (include_data->type == jbvBinary)
|
||||||
{
|
{
|
||||||
JsonbIterator *it = JsonbIteratorInit((JsonbContainer *)include_data->val.binary.data);
|
JsonbIterator *it = JsonbIteratorInit((JsonbContainer *)include_data->val.binary.data);
|
||||||
JsonbIteratorToken token;
|
JsonbIteratorToken token;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ DECLARE
|
|||||||
BEGIN
|
BEGIN
|
||||||
-- Test 1: Complex template with all tag types
|
-- Test 1: Complex template with all tag types
|
||||||
total_tests := total_tests + 1;
|
total_tests := total_tests + 1;
|
||||||
|
BEGIN
|
||||||
test_result := hemar.render(
|
test_result := hemar.render(
|
||||||
'{
|
'{
|
||||||
"page": {
|
"page": {
|
||||||
@@ -121,9 +122,13 @@ BEGIN
|
|||||||
RAISE WARNING 'Test %: Complex template with all tag types: FAILED. Expected "%", got "%"',
|
RAISE WARNING 'Test %: Complex template with all tag types: FAILED. Expected "%", got "%"',
|
||||||
total_tests, expected, test_result;
|
total_tests, expected, test_result;
|
||||||
END IF;
|
END IF;
|
||||||
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
RAISE WARNING 'Test % failed: Error: %', total_tests, SQLERRM;
|
||||||
|
END;
|
||||||
|
|
||||||
-- Test 2: Template with nested includes and shared context
|
-- Test 2: Template with nested includes and shared context
|
||||||
total_tests := total_tests + 1;
|
total_tests := total_tests + 1;
|
||||||
|
BEGIN
|
||||||
test_result := hemar.render(
|
test_result := hemar.render(
|
||||||
'{
|
'{
|
||||||
"user": {
|
"user": {
|
||||||
@@ -159,9 +164,13 @@ BEGIN
|
|||||||
RAISE WARNING 'Test %: Template with nested includes and shared context: FAILED. Expected "%", got "%"',
|
RAISE WARNING 'Test %: Template with nested includes and shared context: FAILED. Expected "%", got "%"',
|
||||||
total_tests, expected, test_result;
|
total_tests, expected, test_result;
|
||||||
END IF;
|
END IF;
|
||||||
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
RAISE WARNING 'Test % failed: Error: %', total_tests, SQLERRM;
|
||||||
|
END;
|
||||||
|
|
||||||
-- Test 3: Template with execute tag using context from section
|
-- Test 3: Template with execute tag using context from section
|
||||||
total_tests := total_tests + 1;
|
total_tests := total_tests + 1;
|
||||||
|
BEGIN
|
||||||
test_result := hemar.render(
|
test_result := hemar.render(
|
||||||
'{
|
'{
|
||||||
"items": [
|
"items": [
|
||||||
@@ -197,6 +206,9 @@ BEGIN
|
|||||||
RAISE WARNING 'Test %: Template with execute tag using context from section: FAILED. Expected "%", got "%"',
|
RAISE WARNING 'Test %: Template with execute tag using context from section: FAILED. Expected "%", got "%"',
|
||||||
total_tests, expected, test_result;
|
total_tests, expected, test_result;
|
||||||
END IF;
|
END IF;
|
||||||
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
RAISE WARNING 'Test % failed: Error: %', total_tests, SQLERRM;
|
||||||
|
END;
|
||||||
|
|
||||||
-- Print summary
|
-- Print summary
|
||||||
IF passed_tests = total_tests THEN
|
IF passed_tests = total_tests THEN
|
||||||
|
|||||||
@@ -177,6 +177,44 @@ BEGIN
|
|||||||
RAISE WARNING 'Test % failed: Should have raised an error for invalid include data', total_tests;
|
RAISE WARNING 'Test % failed: Should have raised an error for invalid include data', total_tests;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
-- Test 8: Error handling - unexisting include object
|
||||||
|
total_tests := total_tests + 1;
|
||||||
|
BEGIN
|
||||||
|
result := hemar.render(
|
||||||
|
'{}'::jsonb,
|
||||||
|
'{{ include invalid_template }}'
|
||||||
|
);
|
||||||
|
|
||||||
|
IF result = '' THEN
|
||||||
|
RAISE NOTICE 'Test % passed: Error handling for unexisting include object works correctly', total_tests;
|
||||||
|
passed_tests := passed_tests + 1;
|
||||||
|
ELSE
|
||||||
|
RAISE WARNING 'Test % failed: Expected "", got "%"', total_tests, result;
|
||||||
|
END IF;
|
||||||
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
RAISE WARNING 'Test % failed: Should have raised an error for unexisting include object', total_tests;
|
||||||
|
END;
|
||||||
|
|
||||||
|
-- Test 9: Error handling - unexisting include data
|
||||||
|
total_tests := total_tests + 1;
|
||||||
|
BEGIN
|
||||||
|
result := hemar.render(
|
||||||
|
'{
|
||||||
|
"include": { }
|
||||||
|
}'::jsonb,
|
||||||
|
'{{ include invalid_template }}'
|
||||||
|
);
|
||||||
|
|
||||||
|
IF result = '' THEN
|
||||||
|
RAISE NOTICE 'Test % passed: Error handling for unexisting include data works correctly', total_tests;
|
||||||
|
passed_tests := passed_tests + 1;
|
||||||
|
ELSE
|
||||||
|
RAISE WARNING 'Test % failed: Expected "", got "%"', total_tests, result;
|
||||||
|
END IF;
|
||||||
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
RAISE WARNING 'Test % failed: Should have raised an error for unexisting include data', total_tests;
|
||||||
|
END;
|
||||||
|
|
||||||
IF passed_tests = total_tests THEN
|
IF passed_tests = total_tests THEN
|
||||||
RAISE NOTICE '------------------------------------';
|
RAISE NOTICE '------------------------------------';
|
||||||
RAISE NOTICE 'SUMMARY: % of % template include tests passed (100%%)',
|
RAISE NOTICE 'SUMMARY: % of % template include tests passed (100%%)',
|
||||||
|
|||||||
Reference in New Issue
Block a user