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

133 lines
5.5 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\Cloud\CloudPublicIpPoolReplacementBatchService;
use App\Services\Cloud\CloudPublicNetworkTransitionBatchPlan;
$root = dirname(__DIR__);
$schema = file_get_contents($root . '/sql/cloud.sql');
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
$itemModel = file_get_contents(
$root . '/app/Models/CloudPublicIpPoolReplacementBatchItem.php'
);
$jobs = file_get_contents($root . '/app/Services/Cloud/CloudJobService.php');
$worker = file_get_contents($root . '/app/Services/Cloud/CloudWorkerService.php');
$recovery = file_get_contents(
$root . '/app/Services/Cloud/CloudOperationRecoveryService.php'
);
$automaticRecovery = file_get_contents(
$root . '/app/Services/Cloud/CloudAutomaticOperationRecoveryService.php'
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(is_string($schema)
&& str_contains($schema,
'CREATE TABLE cloud_public_ip_pool_replacement_batches')
&& str_contains($schema,
'CREATE TABLE cloud_public_ip_pool_replacement_batch_items')
&& str_contains($schema, 'cloud_public_pool_replacement_active')
&& str_contains($schema, 'source_initial_state')
&& str_contains($schema,
"source_initial_state IN ('active','draining')")
&& str_contains($schema, 'source_public_ip_pool_id, active_claim')
&& str_contains($schema, 'target_public_ip_pool_id, active_claim, id')
&& str_contains($schema, 'cloud_public_pool_replacement_child')
&& str_contains($schema, 'address_family TINYINT UNSIGNED NOT NULL')
&& str_contains($schema, 'child_job_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($schema,
'chk_cloud_public_pool_replacement_item_family')
&& str_contains($schema, 'address_family IN (4,6)')
&& str_contains($schema,
"state = 'preparing' AND child_job_id IS NULL")
&& str_contains($schema,
"state IN ('queued','succeeded','failed','unknown')")
&& str_contains($schema, 'AND child_job_id IS NOT NULL')
&& str_contains($schema,
"state IN ('running','blocked','succeeded','failed')"),
'Public-pool replacement lacks durable batch, child, or claim schema.');
$assert(is_string($setup)
&& str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v51-compact-telemetry-storage'")
&& str_contains($setup,
"'cloud_public_ip_pool_replacement_batches'")
&& str_contains($setup,
"'cloud_public_ip_pool_replacement_batch_items'")
&& str_contains($setup,
"'chk_cloud_public_pool_replacement_source_initial'")
&& str_contains($setup,
"'chk_cloud_public_pool_replacement_item_family'")
&& str_contains($setup,
"'chk_cloud_public_pool_replacement_claim'"),
'CloudSetup does not enforce the replacement batch schema.');
$assert(is_string($itemModel)
&& str_contains($itemModel, "'address_family' => 'int'")
&& str_contains($itemModel, "'child_job_id' => 'int'"),
'Replacement batch-item model lost family or child identity casts.');
$service = new ReflectionClass(
CloudPublicIpPoolReplacementBatchService::class
);
$serviceMethods = array_values(array_map(
static fn (ReflectionMethod $method): string => $method->getName(),
array_filter(
$service->getMethods(ReflectionMethod::IS_PUBLIC),
static fn (ReflectionMethod $method): bool =>
$method->getDeclaringClass()->getName()
=== CloudPublicIpPoolReplacementBatchService::class
)
));
sort($serviceMethods, SORT_STRING);
$expectedServiceMethods = [
'overview',
'detail',
'start',
'projectTransitionEvidenceLocked',
'display',
];
sort($expectedServiceMethods, SORT_STRING);
$assert($service->isFinal()
&& $serviceMethods === $expectedServiceMethods,
'Replacement batch public API drifted.');
$plan = new ReflectionClass(CloudPublicNetworkTransitionBatchPlan::class);
$constructor = $plan->getConstructor();
$assert($plan->isFinal() && $constructor instanceof ReflectionMethod,
'Caller-locked replacement plan is missing.');
foreach ($constructor->getParameters() as $parameter) {
$property = $plan->getProperty($parameter->getName());
$assert($property->isPublic() && $property->isReadOnly(),
'Replacement plan input is not an immutable public projection: '
. $parameter->getName());
}
$assert(is_string($jobs)
&& !str_contains($jobs, 'enqueuePoolReplacementNetworkChangeLocked')
&& !str_contains($jobs, 'finishResolvedChildLocked'),
'Retired replacement-specific job writers returned.');
$assert(is_string($worker)
&& !str_contains($worker,
'CloudPublicIpPoolReplacementBatchService::finishChildLocked')
&& str_contains($worker,
'CloudPublicNetworkTransitionWorkflow::finishJobLocked')
&& str_contains($worker, '$aggregateParent')
&& str_contains($worker, "'public_ip_pool_replacement_batch'")
&& is_string($recovery)
&& str_contains($recovery, 'CloudPublicNetworkTransitionWorkflow::')
&& str_contains($recovery, 'publishPreparedLocked(')
&& str_contains($recovery, '$aggregateParent')
&& is_string($automaticRecovery)
&& str_contains(
$automaticRecovery,
'CloudPublicNetworkTransitionWorkflow::'
)
&& str_contains($automaticRecovery, 'retryPendingFinalization('),
'Worker or recovery no longer uses the canonical transition facade.');
echo "Cloud public IP pool replacement schema contract tests passed\n";