mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-20 04:23:34 +00:00
Fix Vultr power controls for stopped instances
This commit is contained in:
@@ -31,7 +31,7 @@ class VultrService
|
||||
throw new \Exception('Vultr API error: '.$response->json('error', 'Unknown error'), $response->status());
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
return $response->json() ?? [];
|
||||
}
|
||||
|
||||
private function requestPaginated(string $endpoint, string $resourceKey, array $data = []): array
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
@if ($server->cloudProviderToken && !$server->isFunctional() && $vultrInstanceStatus === 'stopped')
|
||||
@if ($server->cloudProviderToken && $vultrInstanceStatus === 'stopped')
|
||||
<x-forms.button wire:click.prevent='startVultrInstance' isHighlighted canGate="update"
|
||||
:canResource="$server">
|
||||
Power On
|
||||
|
||||
@@ -236,6 +236,23 @@ it('blocks action validation when Vultr instance is stopped', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('shows Vultr power on button when stopped even if server was previously functional', function () {
|
||||
$this->server->update([
|
||||
'ip' => '1.2.3.5',
|
||||
'vultr_instance_status' => 'stopped',
|
||||
]);
|
||||
$this->server->settings->update([
|
||||
'is_reachable' => true,
|
||||
'is_usable' => true,
|
||||
'force_disabled' => false,
|
||||
]);
|
||||
|
||||
expect($this->server->fresh()->isFunctional())->toBeTrue();
|
||||
|
||||
Livewire::test(Show::class, ['server_uuid' => $this->server->uuid])
|
||||
->assertSee('Power On');
|
||||
});
|
||||
|
||||
it('starts a Vultr instance', function () {
|
||||
Http::fake([
|
||||
'https://api.vultr.com/v2/instances/instance-1/start' => Http::response([], 204),
|
||||
|
||||
@@ -136,3 +136,17 @@ it('finds an instance by IPv4 or IPv6', function () {
|
||||
->and($service->findInstanceByIp('2001:db8::1')['id'])->toBe('instance-1')
|
||||
->and($service->findInstanceByIp('1.2.3.4'))->toBeNull();
|
||||
});
|
||||
|
||||
it('handles empty successful responses from Vultr API', function () {
|
||||
Http::fake([
|
||||
'https://api.vultr.com/v2/instances/instance-1/start' => Http::response(null, 204),
|
||||
'https://api.vultr.com/v2/instances/instance-1' => Http::response(null, 204),
|
||||
]);
|
||||
|
||||
$service = new VultrService('fake-token');
|
||||
|
||||
expect($service->startInstance('instance-1'))->toBe([]);
|
||||
$service->deleteInstance('instance-1');
|
||||
|
||||
Http::assertSentCount(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user