Skip to content

Commit 7546d54

Browse files
committed
Add test coverage for resource utilization
1 parent 6312b62 commit 7546d54

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Pterodactyl\Tests\Integration\Api\Client\Server;
4+
5+
use Mockery;
6+
use Pterodactyl\Models\Permission;
7+
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
8+
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
9+
10+
class ResourceUtilitizationControllerTest extends ClientApiIntegrationTestCase
11+
{
12+
/**
13+
* Test that the resource utilization for a server is returned in the expected format.
14+
*/
15+
public function testServerResourceUtilizationIsReturned()
16+
{
17+
$service = Mockery::mock(DaemonServerRepository::class);
18+
$this->app->instance(DaemonServerRepository::class, $service);
19+
20+
[$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]);
21+
22+
$service->expects('setServer')->with(Mockery::on(function ($value) use ($server) {
23+
return $server->uuid === $value->uuid;
24+
}))->andReturnSelf()->getMock()->expects('getDetails')->andReturns([]);
25+
26+
$response = $this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/resources");
27+
28+
$response->assertOk();
29+
$response->assertJson([
30+
'object' => 'stats',
31+
'attributes' => [
32+
'current_state' => 'stopped',
33+
'is_suspended' => false,
34+
'resources' => [
35+
'memory_bytes' => 0,
36+
'cpu_absolute' => 0,
37+
'disk_bytes' => 0,
38+
'network_rx_bytes' => 0,
39+
'network_tx_bytes' => 0,
40+
],
41+
],
42+
]);
43+
}
44+
}

0 commit comments

Comments
 (0)