49 lines
1.8 KiB
PHP
49 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Models\Host;
|
|
use App\Services\Proxmox\FakeProxmoxClient;
|
|
use App\Services\Ssh\CommandResult;
|
|
use App\Services\Ssh\FakeRemoteShell;
|
|
use App\Services\Wireguard\FakeWireguardHub;
|
|
|
|
it('scripts remote command output and records calls (FakeRemoteShell)', function () {
|
|
$shell = new FakeRemoteShell;
|
|
$shell->script('dpkg -l proxmox-ve', CommandResult::success('ii proxmox-ve 8.2'));
|
|
$shell->connectWithPassword('1.2.3.4', 'root', 'pw');
|
|
|
|
expect($shell->run('dpkg -l proxmox-ve')->stdout)->toContain('proxmox-ve')
|
|
->and($shell->run('whoami')->ok())->toBeTrue() // default success
|
|
->and($shell->ran('dpkg -l proxmox-ve'))->toBeTrue();
|
|
|
|
$shell->putFile('/etc/wireguard/wg0.conf', '[Interface]');
|
|
expect($shell->files()['/etc/wireguard/wg0.conf'])->toBe('[Interface]')
|
|
->and($shell->connectionsWith('password'))->toHaveCount(1);
|
|
});
|
|
|
|
it('allocates ips and tracks peers (FakeWireguardHub)', function () {
|
|
$hub = new FakeWireguardHub;
|
|
|
|
$a = $hub->allocateIp();
|
|
$b = $hub->allocateIp();
|
|
expect($a)->not->toBe($b);
|
|
|
|
$hub->addPeer('PUBKEY', '10.66.0.9');
|
|
expect($hub->peers())->toBe(['PUBKEY' => '10.66.0.9']);
|
|
|
|
$hub->removePeer('PUBKEY');
|
|
expect($hub->peers())->toBe([]);
|
|
});
|
|
|
|
it('reports capacity and mints a token for a host (FakeProxmoxClient)', function () {
|
|
$host = Host::factory()->create(['wg_ip' => '10.66.0.5']);
|
|
$client = (new FakeProxmoxClient)->forHost($host);
|
|
|
|
expect($client->listNodes())->not->toBeEmpty()
|
|
->and($client->nodeStatus('pve')['memory']['total'])->toBeGreaterThan(0)
|
|
->and($client->nodeStorage('pve')[0]['total'])->toBeGreaterThan(0);
|
|
|
|
$token = $client->createUserAndToken('automation@pve', 'CluPilotAutomation');
|
|
expect($token)->toHaveKeys(['token_id', 'secret'])
|
|
->and($client->tokenCalls)->toBe(1);
|
|
});
|