You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudTemplateImportIntentCo...

45 lines
1.9 KiB
PHP

<?php
$root = dirname(__DIR__);
$schema = file_get_contents($root . '/sql/cloud.sql');
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
$routes = file_get_contents($root . '/config/routes_cloud.php');
$controller = file_get_contents(
$root . '/app/Controllers/CloudAdminController.php'
);
if (!is_string($schema) || !is_string($setup) || !is_string($routes)
|| !is_string($controller)) {
throw new RuntimeException('Template-import contract sources are unreadable.');
}
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
foreach (['cloud_template_import_intents',
'cloud_template_import_parts'] as $table) {
$assert(str_contains($schema, 'CREATE TABLE ' . $table . ' ('),
'Missing template-import table: ' . $table);
$assert(str_contains($setup, "'" . $table . "'"),
'CloudSetup does not require template-import table: ' . $table);
}
$assert(str_contains($schema,
'UNIQUE KEY cloud_template_import_request (user_id, request_idempotency_key)')
&& str_contains($schema,
'UNIQUE KEY cloud_template_import_template (template_id)')
&& str_contains($schema,
'UNIQUE KEY cloud_template_import_object (object_key)')
&& str_contains($schema,
'CONSTRAINT chk_cloud_template_import_completion CHECK (')
&& str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v19-template-import-intents'"),
'Template imports are missing durable identity or terminal-state constraints.');
$assert(str_contains($routes, "'/admin/cloud-template-imports'")
&& str_contains($routes, "'/admin/cloud-template-imports/{id}'")
&& str_contains($controller, 'CloudTemplateImportWorkflow')
&& str_contains($controller, 'beginUpload('),
'Administrator template-import intent routes are not wired.');
echo "Cloud-template import intent schema and route contract passed.\n";