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/CloudPublicIpPoolReplacemen...

66 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
$root = dirname(__DIR__);
$routes = file_get_contents($root . '/config/routes_cloud.php');
$controller = file_get_contents(
$root . '/app/Controllers/CloudAdminPublicIpPoolReplacementController.php'
);
$service = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicIpPoolReplacementBatchService.php'
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(is_string($routes) && str_contains(
$routes,
'/network-pools/{pool_key:[0-9a-f]{32}}/replacement-batches'
), 'Public-pool replacement collection route is missing.');
$assert(str_contains(
$routes,
'/replacement-batches/{batch_key:[0-9a-f]{32}}'
), 'Public-pool replacement detail route is missing.');
$receiptMatch = [];
$receiptMatched = preg_match(
'/return \\$response->withJson\(\[\s*(.*?)\s*\],\s*202\)/s',
(string) $controller,
$receiptMatch
) === 1;
$receiptKeys = [];
if ($receiptMatched) {
preg_match_all(
"/'([a-z_]+)'\\s*=>/",
(string) ($receiptMatch[1] ?? ''),
$receiptKeys
);
}
$receiptKeys = array_values(array_unique($receiptKeys[1] ?? []));
sort($receiptKeys);
$assert(is_string($controller)
&& str_contains($controller, "'confirm_replacement'")
&& str_contains($controller, "'expected_source_revision'")
&& str_contains($controller, "'expected_target_revision'")
&& $receiptMatched
&& $receiptKeys === ['status_url', 'task_id'],
'Replacement controller lost its strict input or 202 task receipt.');
$assert(is_string($service)
&& str_contains($service, "'target_pool_key'")
&& !str_contains($controller, "'instance_ids'")
&& !str_contains($controller, "'target_public_ip_id'"),
'The browser boundary can select instances or target IPs directly.');
$assert(str_contains(
$service,
'beginPoolReplacementBatch('
) && str_contains(
$service,
'new CloudPublicNetworkTransitionBatchPlan('
) && str_contains($service, "'active_claim', 1")
&& str_contains($service, "'network_change_effect_unknown'"),
'Replacement service lost durable child jobs or unknown-effect fencing.');
echo "Public-pool replacement HTTP contract passed.\n";