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

87 lines
3.9 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\Cloud\CloudPortableRestoreTargetService;
$root = dirname(__DIR__);
$service = (string) file_get_contents(
$root . '/app/Services/Cloud/CloudPortableRestoreTargetService.php'
);
$network = (string) file_get_contents(
$root . '/app/Services/Cloud/CloudPlacementNetworkService.php'
);
$plan = (string) file_get_contents(
$root . '/app/Services/Cloud/CloudPortableRestoreTargetPlan.php'
);
$evidence = (string) file_get_contents(
$root . '/app/Services/Cloud/CloudPortableRestoreBackupEvidence.php'
);
$backup = (string) file_get_contents(
$root . '/app/Services/Cloud/CloudBackupService.php'
);
$request = (string) file_get_contents(
$root . '/app/Services/Cloud/CloudPortableRestoreRequestService.php'
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$public = array_values(array_filter(
(new ReflectionClass(CloudPortableRestoreTargetService::class))
->getMethods(ReflectionMethod::IS_PUBLIC),
static fn (ReflectionMethod $method): bool =>
$method->getDeclaringClass()->getName()
=== CloudPortableRestoreTargetService::class
));
$assert(count($public) === 1 && $public[0]->getName() === 'candidates',
'Portable restore target scheduler exposed more than one interface method.');
$assert(str_contains($network, 'advisoryDualStackBundleEvidence')
&& str_contains($network, '$available[$hostId][$lineId][]')
&& str_contains($network, "'network_attachment_id'")
&& str_contains($network, "'ipv4' => \$families[4]")
&& str_contains($network, "'ipv6' => \$families[6]"),
'Dual-stack advisory evidence lost host+line or same-attachment identity.');
$assert(str_contains($service, '->getConnection()->transaction(')
&& str_contains($service, 'advisoryDualStackBundleEvidence(')
&& !str_contains($service, 'backupRestoreTargets(')
&& !str_contains($service, 'advisoryDualStackAvailableHosts(')
&& str_contains($service, 'CloudPortableRestoreBackupEvidence::fromBackup(')
&& str_contains($evidence, 'object_identity_sha256')
&& str_contains($evidence, 'source_public_network_sha256')
&& str_contains($evidence, 'source_spec_sha256')
&& str_contains($evidence, 'restore_request_sha256')
&& str_contains($plan, 'public static function fromEvidence(')
&& str_contains($plan, 'self::exactKeys(')
&& str_contains($plan, "'address_family'")
&& str_contains($plan, "'vpc_inherited'")
&& !str_contains($plan, 'public static function freeze('),
'Plan validation or one-snapshot advisory evidence was weakened.');
foreach (['->save(', '->insert(', 'insertGetId(', '->update(',
'->delete(', 'lockForUpdate(', 'headObject(', 'presignedGet('] as $write) {
$assert(!str_contains($service, $write),
'Portable restore target scheduler gained a side effect: ' . $write);
}
$assert(str_contains($request, 'CloudPortableRestoreTargetService::candidates(')
&& str_contains($request,
'CloudPortableRestoreAttemptCoordinator::reserve(')
&& str_contains($request, 'CloudPortableRestoreJobDispatcher::queue(')
&& str_contains($request, 'target_plan_sha256')
&& str_contains($backup, 'CloudPortableRestoreRequestService::request(')
&& str_contains($backup,
'CloudPortableRestoreTargetService::candidates(')
&& substr_count($backup, 'self::restoreTargetProjection($row)') >= 2
&& str_contains($backup, "'target_plan_sha256' => \$plan->sha256()")
&& !str_contains($backup,
'CloudPlacementService::backupRestoreTargets(\n'
. ' (int) \$row->source_host_id')
&& !str_contains(
$backup,
'CloudPublicNetworkTransitionGate::assertPortableRestoreReady();'
),
'Restore entry did not connect exclusively through the frozen portable plan.');
echo "Portable restore target scheduling contract passed.\n";