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.
59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudError;
|
|
use App\Services\Cloud\CloudVpcProjection;
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$vpc = [
|
|
'vpc_key' => '0123456789abcdef0123456789abcdef',
|
|
'cidr' => '10.60.0.0/24',
|
|
'gateway' => '10.60.0.1',
|
|
];
|
|
$ports = [
|
|
['private_ip' => '10.60.0.9', 'mac_address' => '02:00:00:00:00:09',
|
|
'host_id' => 1],
|
|
['private_ip' => '10.60.0.2', 'mac_address' => '02:00:00:00:00:02',
|
|
'host_id' => 1],
|
|
['private_ip' => '10.60.0.8', 'mac_address' => '02:00:00:00:00:08',
|
|
'host_id' => 2],
|
|
['private_ip' => '10.60.0.3', 'mac_address' => '02:00:00:00:00:03',
|
|
'host_id' => 2],
|
|
];
|
|
$transports = [
|
|
1 => ['transport_address' => '172.16.10.11',
|
|
'transport_prefix_length' => 24,
|
|
'transport_interface' => 'br-private', 'mtu' => 1500],
|
|
2 => ['transport_address' => '172.16.10.12',
|
|
'transport_prefix_length' => 24,
|
|
'transport_interface' => 'br-private', 'mtu' => 1500],
|
|
];
|
|
$projection = CloudVpcProjection::build($vpc, $ports, $transports, 3);
|
|
$assert($projection[1]['digest']
|
|
=== 'c14a86ae5ec448e9977c9da5102d82889b5c705896474f43cb2af38977ad64e2',
|
|
'PHP projection digest drifted from Go json.Marshal contract.');
|
|
$assert($projection[1]['network']['local_ports'][0]['ip'] === '10.60.0.2'
|
|
&& $projection[1]['network']['peer_routes'][0]['ip'] === '10.60.0.3',
|
|
'Projection addresses were not canonically sorted.');
|
|
$assert(CloudVpcProjection::bridgeName($vpc['vpc_key'])
|
|
=== 'vcfefd87aeec7b',
|
|
'PHP bridge name drifted from the Agent derivation.');
|
|
|
|
try {
|
|
$invalid = $transports;
|
|
$invalid[2]['transport_address'] = '172.16.11.12';
|
|
CloudVpcProjection::build($vpc, $ports, $invalid, 3);
|
|
throw new RuntimeException('Off-link VPC underlay was accepted.');
|
|
} catch (CloudError $error) {
|
|
$assert($error->httpStatus === 409,
|
|
'Off-link VPC underlay returned the wrong status.');
|
|
}
|
|
|
|
echo "VPC projection and Go digest contract passed.\n";
|