51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Services\Agent\AgentClient;
|
|
use Tests\TestCase;
|
|
|
|
class JabaliSyncCgroupsTest extends TestCase
|
|
{
|
|
public function test_syncs_all_processes(): void
|
|
{
|
|
$this->app->instance(AgentClient::class, new FakeAgentClient([
|
|
'success' => true,
|
|
'moved' => 4,
|
|
]));
|
|
|
|
$this->artisan('jabali:sync-cgroups')
|
|
->expectsOutput('Synced cgroups, moved 4 process(es).')
|
|
->assertExitCode(0);
|
|
}
|
|
|
|
public function test_syncs_single_user(): void
|
|
{
|
|
$this->app->instance(AgentClient::class, new FakeAgentClient([
|
|
'success' => true,
|
|
'moved' => 1,
|
|
]));
|
|
|
|
$this->artisan('jabali:sync-cgroups --user=testuser')
|
|
->expectsOutput('Synced cgroups, moved 1 process(es).')
|
|
->assertExitCode(0);
|
|
}
|
|
}
|
|
|
|
class FakeAgentClient extends AgentClient
|
|
{
|
|
public function __construct(private array $result) {}
|
|
|
|
public function cgroupSyncUserProcesses(string $username): array
|
|
{
|
|
return $this->result;
|
|
}
|
|
|
|
public function cgroupSyncAllProcesses(): array
|
|
{
|
|
return $this->result;
|
|
}
|
|
}
|