Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Integration/Api/Client/Server/ResourceUtilizationControllerTest.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Tests\Integration\Api\Client\Server;
4
5
use Pterodactyl\Models\Permission;
6
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
7
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
8
9
class ResourceUtilizationControllerTest extends ClientApiIntegrationTestCase
10
{
11
/**
12
* Test that the resource utilization for a server is returned in the expected format.
13
*/
14
public function testServerResourceUtilizationIsReturned()
15
{
16
$service = \Mockery::mock(DaemonServerRepository::class);
17
$this->app->instance(DaemonServerRepository::class, $service);
18
19
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
20
21
$service->expects('setServer')->with(\Mockery::on(function ($value) use ($server) {
22
return $server->uuid === $value->uuid;
23
}))->andReturnSelf()->getMock()->expects('getDetails')->andReturns([]);
24
25
$response = $this->actingAs($user)->getJson("/api/client/servers/$server->uuid/resources");
26
27
$response->assertOk();
28
$response->assertJson([
29
'object' => 'stats',
30
'attributes' => [
31
'current_state' => 'stopped',
32
'is_suspended' => false,
33
'resources' => [
34
'memory_bytes' => 0,
35
'cpu_absolute' => 0,
36
'disk_bytes' => 0,
37
'network_rx_bytes' => 0,
38
'network_tx_bytes' => 0,
39
],
40
],
41
]);
42
}
43
}
44
45