Update some server service tests
This commit is contained in:
parent
83a59cdf4f
commit
b55767426f
6 changed files with 117 additions and 165 deletions
|
@ -4,8 +4,8 @@ namespace Pterodactyl\Services\Servers;
|
||||||
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
||||||
|
|
||||||
class ReinstallServerService
|
class ReinstallServerService
|
||||||
{
|
{
|
||||||
|
@ -17,27 +17,27 @@ class ReinstallServerService
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\ConnectionInterface
|
* @var \Illuminate\Database\ConnectionInterface
|
||||||
*/
|
*/
|
||||||
private $database;
|
private $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||||
*/
|
*/
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReinstallService constructor.
|
* ReinstallService constructor.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\ConnectionInterface $database
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ConnectionInterface $database,
|
ConnectionInterface $connection,
|
||||||
DaemonServerRepository $daemonServerRepository,
|
DaemonServerRepository $daemonServerRepository,
|
||||||
ServerRepositoryInterface $repository
|
ServerRepository $repository
|
||||||
) {
|
) {
|
||||||
$this->daemonServerRepository = $daemonServerRepository;
|
$this->daemonServerRepository = $daemonServerRepository;
|
||||||
$this->database = $database;
|
$this->connection = $connection;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,14 +51,14 @@ class ReinstallServerService
|
||||||
*/
|
*/
|
||||||
public function reinstall(Server $server)
|
public function reinstall(Server $server)
|
||||||
{
|
{
|
||||||
$this->database->transaction(function () use ($server) {
|
return $this->connection->transaction(function () use ($server) {
|
||||||
$this->repository->withoutFreshModel()->update($server->id, [
|
$updated = $this->repository->update($server->id, [
|
||||||
'installed' => Server::STATUS_INSTALLING,
|
'installed' => Server::STATUS_INSTALLING,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->daemonServerRepository->setServer($server)->reinstall();
|
$this->daemonServerRepository->setServer($server)->reinstall();
|
||||||
});
|
|
||||||
|
|
||||||
return $server->refresh();
|
return $updated;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,8 +310,6 @@ class ServerCreationService
|
||||||
return $allocation->node_id;
|
return $allocation->node_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection PhpDocMissingThrowsInspection */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a unique UUID and UUID-Short combo for a server.
|
* Create a unique UUID and UUID-Short combo for a server.
|
||||||
*
|
*
|
||||||
|
@ -319,7 +317,6 @@ class ServerCreationService
|
||||||
*/
|
*/
|
||||||
private function generateUniqueUuidCombo(): string
|
private function generateUniqueUuidCombo(): string
|
||||||
{
|
{
|
||||||
/** @noinspection PhpUnhandledExceptionInspection */
|
|
||||||
$uuid = Uuid::uuid4()->toString();
|
$uuid = Uuid::uuid4()->toString();
|
||||||
|
|
||||||
if (! $this->repository->isUniqueUuidCombo($uuid, substr($uuid, 0, 8))) {
|
if (! $this->repository->isUniqueUuidCombo($uuid, substr($uuid, 0, 8))) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ use Pterodactyl\Models\Pack;
|
||||||
use Illuminate\Contracts\Filesystem\Factory;
|
use Illuminate\Contracts\Filesystem\Factory;
|
||||||
use Pterodactyl\Services\Packs\ExportPackService;
|
use Pterodactyl\Services\Packs\ExportPackService;
|
||||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||||
|
use Pterodactyl\Exceptions\Service\Pack\ZipArchiveCreationException;
|
||||||
|
|
||||||
class ExportPackServiceTest extends TestCase
|
class ExportPackServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -132,11 +133,11 @@ class ExportPackServiceTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that an exception is thrown when a ZipArchive cannot be created.
|
* Test that an exception is thrown when a ZipArchive cannot be created.
|
||||||
*
|
|
||||||
* @expectedException \Pterodactyl\Exceptions\Service\Pack\ZipArchiveCreationException
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionIsThrownIfZipArchiveCannotBeCreated()
|
public function testExceptionIsThrownIfZipArchiveCannotBeCreated()
|
||||||
{
|
{
|
||||||
|
$this->expectException(ZipArchiveCreationException::class);
|
||||||
|
|
||||||
$this->setupTestData();
|
$this->setupTestData();
|
||||||
|
|
||||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Packs', 'tempnam')
|
$this->getFunctionMock('\\Pterodactyl\\Services\\Packs', 'tempnam')
|
||||||
|
|
|
@ -9,48 +9,30 @@
|
||||||
|
|
||||||
namespace Tests\Unit\Services\Servers;
|
namespace Tests\Unit\Services\Servers;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use GuzzleHttp\Psr7\Response;
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
use Pterodactyl\Services\Servers\ReinstallServerService;
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
|
||||||
|
|
||||||
class ReinstallServerServiceTest extends TestCase
|
class ReinstallServerServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||||
*/
|
*/
|
||||||
protected $daemonServerRepository;
|
private $daemonServerRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\ConnectionInterface
|
* @var \Illuminate\Database\ConnectionInterface
|
||||||
*/
|
*/
|
||||||
protected $database;
|
private $connection;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \GuzzleHttp\Exception\RequestException
|
|
||||||
*/
|
|
||||||
protected $exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Models\Server
|
|
||||||
*/
|
|
||||||
protected $server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Servers\ReinstallServerService
|
|
||||||
*/
|
|
||||||
protected $service;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup tests.
|
* Setup tests.
|
||||||
|
@ -59,18 +41,9 @@ class ReinstallServerServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->daemonServerRepository = m::mock(DaemonServerRepositoryInterface::class);
|
$this->repository = m::mock(ServerRepository::class);
|
||||||
$this->database = m::mock(ConnectionInterface::class);
|
$this->connection = m::mock(ConnectionInterface::class);
|
||||||
$this->exception = m::mock(RequestException::class)->makePartial();
|
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
|
||||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
|
||||||
|
|
||||||
$this->server = factory(Server::class)->make(['node_id' => 1]);
|
|
||||||
|
|
||||||
$this->service = new ReinstallServerService(
|
|
||||||
$this->database,
|
|
||||||
$this->daemonServerRepository,
|
|
||||||
$this->repository
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,70 +51,32 @@ class ReinstallServerServiceTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testServerShouldBeReinstalledWhenModelIsPassed()
|
public function testServerShouldBeReinstalledWhenModelIsPassed()
|
||||||
{
|
{
|
||||||
$this->repository->shouldNotReceive('find');
|
/** @var \Pterodactyl\Models\Server $server */
|
||||||
|
$server = factory(Server::class)->make(['id' => 123]);
|
||||||
|
$updated = clone $server;
|
||||||
|
$updated->installed = Server::STATUS_INSTALLING;
|
||||||
|
|
||||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
$this->connection->expects('transaction')->with(m::on(function ($closure) use ($updated) {
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($this->server->id, [
|
return $closure() instanceof Server;
|
||||||
'installed' => 0,
|
}))->andReturn($updated);
|
||||||
], true, true)->once()->andReturnNull();
|
|
||||||
|
|
||||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
$this->repository->expects('update')->with($server->id, [
|
||||||
->shouldReceive('reinstall')->withNoArgs()->once()->andReturn(new Response);
|
'installed' => Server::STATUS_INSTALLING,
|
||||||
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
])->andReturns($updated);
|
||||||
|
|
||||||
$this->service->reinstall($this->server);
|
$this->daemonServerRepository->expects('setServer')->with($server)->andReturnSelf();
|
||||||
|
$this->daemonServerRepository->expects('reinstall')->withNoArgs();
|
||||||
|
|
||||||
|
$this->assertSame($updated, $this->getService()->reinstall($server));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that a server is reinstalled when the ID of the server is passed to the function.
|
* @return \Pterodactyl\Services\Servers\ReinstallServerService
|
||||||
*/
|
*/
|
||||||
public function testServerShouldBeReinstalledWhenServerIdIsPassed()
|
private function getService()
|
||||||
{
|
{
|
||||||
$this->repository->shouldReceive('find')->with($this->server->id)->once()->andReturn($this->server);
|
return new ReinstallServerService(
|
||||||
|
$this->connection, $this->daemonServerRepository, $this->repository
|
||||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
);
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($this->server->id, [
|
|
||||||
'installed' => 0,
|
|
||||||
], true, true)->once()->andReturnNull();
|
|
||||||
|
|
||||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
|
||||||
->shouldReceive('reinstall')->withNoArgs()->once()->andReturn(new Response);
|
|
||||||
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
|
||||||
|
|
||||||
$this->service->reinstall($this->server->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that an exception thrown by guzzle is rendered as a displayable exception.
|
|
||||||
*
|
|
||||||
* @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
*/
|
|
||||||
public function testExceptionThrownByGuzzleShouldBeReRenderedAsDisplayable()
|
|
||||||
{
|
|
||||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($this->server->id, [
|
|
||||||
'installed' => 0,
|
|
||||||
], true, true)->once()->andReturnNull();
|
|
||||||
|
|
||||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andThrow($this->exception);
|
|
||||||
|
|
||||||
$this->service->reinstall($this->server);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that an exception thrown by something other than guzzle is not transformed to a displayable.
|
|
||||||
*
|
|
||||||
* @expectedException \Exception
|
|
||||||
*/
|
|
||||||
public function testExceptionNotThrownByGuzzleShouldNotBeTransformedToDisplayable()
|
|
||||||
{
|
|
||||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($this->server->id, [
|
|
||||||
'installed' => 0,
|
|
||||||
], true, true)->once()->andReturnNull();
|
|
||||||
|
|
||||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andThrow(new Exception());
|
|
||||||
|
|
||||||
$this->service->reinstall($this->server);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,53 +40,62 @@ class ServerConfigurationStructureServiceTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testCorrectStructureIsReturned()
|
public function testCorrectStructureIsReturned()
|
||||||
{
|
{
|
||||||
|
/** @var \Pterodactyl\Models\Server $model */
|
||||||
$model = factory(Server::class)->make();
|
$model = factory(Server::class)->make();
|
||||||
$model->setRelation('pack', null);
|
$model->setRelation('pack', null);
|
||||||
$model->setRelation('allocation', factory(Allocation::class)->make());
|
$model->setRelation('allocation', factory(Allocation::class)->make());
|
||||||
$model->setRelation('allocations', collect(factory(Allocation::class)->times(2)->make()));
|
$model->setRelation('allocations', collect(factory(Allocation::class)->times(2)->make()));
|
||||||
$model->setRelation('egg', factory(Egg::class)->make());
|
$model->setRelation('egg', factory(Egg::class)->make());
|
||||||
|
|
||||||
$portListing = $model->allocations->groupBy('ip')->map(function ($item) {
|
$this->environment->expects('handle')->with($model)->andReturn(['environment_array']);
|
||||||
return $item->pluck('port');
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
$this->repository->shouldReceive('getDataForCreation')->with($model)->once()->andReturn($model);
|
|
||||||
$this->environment->shouldReceive('handle')->with($model)->once()->andReturn(['environment_array']);
|
|
||||||
|
|
||||||
$response = $this->getService()->handle($model);
|
$response = $this->getService()->handle($model);
|
||||||
$this->assertNotEmpty($response);
|
$this->assertNotEmpty($response);
|
||||||
$this->assertArrayNotHasKey('user', $response);
|
$this->assertArrayNotHasKey('user', $response);
|
||||||
$this->assertArrayNotHasKey('keys', $response);
|
$this->assertArrayNotHasKey('keys', $response);
|
||||||
|
|
||||||
$this->assertArrayHasKey('uuid', $response);
|
$this->assertArrayHasKey('uuid', $response);
|
||||||
|
$this->assertArrayHasKey('suspended', $response);
|
||||||
|
$this->assertArrayHasKey('environment', $response);
|
||||||
|
$this->assertArrayHasKey('invocation', $response);
|
||||||
$this->assertArrayHasKey('build', $response);
|
$this->assertArrayHasKey('build', $response);
|
||||||
$this->assertArrayHasKey('service', $response);
|
$this->assertArrayHasKey('service', $response);
|
||||||
$this->assertArrayHasKey('rebuild', $response);
|
$this->assertArrayHasKey('container', $response);
|
||||||
$this->assertArrayHasKey('suspended', $response);
|
$this->assertArrayHasKey('allocations', $response);
|
||||||
|
|
||||||
$this->assertArraySubset([
|
$this->assertSame([
|
||||||
'default' => [
|
'default' => [
|
||||||
'ip' => $model->allocation->ip,
|
'ip' => $model->allocation->ip,
|
||||||
'port' => $model->allocation->port,
|
'port' => $model->allocation->port,
|
||||||
],
|
],
|
||||||
], $response['build'], true, 'Assert server default allocation is correct.');
|
'mappings' => $model->getAllocationMappings(),
|
||||||
$this->assertArraySubset(['ports' => $portListing], $response['build'], true, 'Assert server ports are correct.');
|
], $response['allocations']);
|
||||||
$this->assertArraySubset([
|
|
||||||
'env' => ['environment_array'],
|
|
||||||
'swap' => (int) $model->swap,
|
|
||||||
'io' => (int) $model->io,
|
|
||||||
'cpu' => (int) $model->cpu,
|
|
||||||
'disk' => (int) $model->disk,
|
|
||||||
'image' => $model->image,
|
|
||||||
], $response['build'], true, 'Assert server build data is correct.');
|
|
||||||
|
|
||||||
$this->assertArraySubset([
|
$this->assertSame([
|
||||||
|
'memory_limit' => $model->memory,
|
||||||
|
'swap' => $model->swap,
|
||||||
|
'io_weight' => $model->io,
|
||||||
|
'cpu_limit' => $model->cpu,
|
||||||
|
'threads' => $model->threads,
|
||||||
|
'disk_space' => $model->disk,
|
||||||
|
], $response['build']);
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
'egg' => $model->egg->uuid,
|
'egg' => $model->egg->uuid,
|
||||||
'pack' => null,
|
'pack' => null,
|
||||||
'skip_scripts' => $model->skip_scripts,
|
'skip_scripts' => $model->skip_scripts,
|
||||||
], $response['service']);
|
], $response['service']);
|
||||||
|
|
||||||
$this->assertFalse($response['rebuild']);
|
$this->assertSame([
|
||||||
$this->assertSame((int) $model->suspended, $response['suspended']);
|
'image' => $model->image,
|
||||||
|
'oom_disabled' => $model->oom_disabled,
|
||||||
|
'requires_rebuild' => false,
|
||||||
|
], $response['container']);
|
||||||
|
|
||||||
|
$this->assertSame($model->uuid, $response['uuid']);
|
||||||
|
$this->assertSame((bool) $model->suspended, $response['suspended']);
|
||||||
|
$this->assertSame(['environment_array'], $response['environment']);
|
||||||
|
$this->assertSame($model->startup, $response['invocation']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,24 +5,27 @@ namespace Tests\Unit\Services\Servers;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Pterodactyl\Models\Egg;
|
use Pterodactyl\Models\Egg;
|
||||||
|
use GuzzleHttp\Psr7\Request;
|
||||||
use Pterodactyl\Models\User;
|
use Pterodactyl\Models\User;
|
||||||
use Tests\Traits\MocksUuids;
|
use Tests\Traits\MocksUuids;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Pterodactyl\Models\Allocation;
|
use Pterodactyl\Models\Allocation;
|
||||||
use Tests\Traits\MocksRequestException;
|
use Tests\Traits\MocksRequestException;
|
||||||
|
use GuzzleHttp\Exception\ConnectException;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Pterodactyl\Models\Objects\DeploymentObject;
|
use Pterodactyl\Models\Objects\DeploymentObject;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
use Pterodactyl\Services\Servers\ServerCreationService;
|
use Pterodactyl\Services\Servers\ServerCreationService;
|
||||||
|
use Pterodactyl\Services\Servers\ServerDeletionService;
|
||||||
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||||
use Pterodactyl\Services\Servers\VariableValidatorService;
|
use Pterodactyl\Services\Servers\VariableValidatorService;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||||
use Pterodactyl\Services\Deployment\FindViableNodesService;
|
use Pterodactyl\Services\Deployment\FindViableNodesService;
|
||||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
|
||||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
||||||
use Pterodactyl\Services\Deployment\AllocationSelectionService;
|
use Pterodactyl\Services\Deployment\AllocationSelectionService;
|
||||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||||
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
|
@ -32,60 +35,60 @@ class ServerCreationServiceTest extends TestCase
|
||||||
use MocksRequestException, MocksUuids;
|
use MocksRequestException, MocksUuids;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $allocationRepository;
|
private $allocationRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Deployment\AllocationSelectionService|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $allocationSelectionService;
|
private $allocationSelectionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $configurationStructureService;
|
private $configurationStructureService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $daemonServerRepository;
|
private $daemonServerRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $eggRepository;
|
private $eggRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Deployment\FindViableNodesService|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $findViableNodesService;
|
private $findViableNodesService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
*/
|
||||||
private $serverVariableRepository;
|
private $serverVariableRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
|
* @var \Mockery\MockInterface
|
||||||
*/
|
|
||||||
private $userRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Servers\VariableValidatorService|\Mockery\Mock
|
|
||||||
*/
|
*/
|
||||||
private $validatorService;
|
private $validatorService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Mockery\MockInterface
|
||||||
|
*/
|
||||||
|
private $serverDeletionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup tests.
|
* Setup tests.
|
||||||
*/
|
*/
|
||||||
|
@ -93,17 +96,17 @@ class ServerCreationServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->allocationRepository = m::mock(AllocationRepositoryInterface::class);
|
$this->allocationRepository = m::mock(AllocationRepository::class);
|
||||||
$this->allocationSelectionService = m::mock(AllocationSelectionService::class);
|
$this->allocationSelectionService = m::mock(AllocationSelectionService::class);
|
||||||
$this->configurationStructureService = m::mock(ServerConfigurationStructureService::class);
|
$this->configurationStructureService = m::mock(ServerConfigurationStructureService::class);
|
||||||
$this->connection = m::mock(ConnectionInterface::class);
|
$this->connection = m::mock(ConnectionInterface::class);
|
||||||
$this->daemonServerRepository = m::mock(DaemonServerRepositoryInterface::class);
|
|
||||||
$this->eggRepository = m::mock(EggRepositoryInterface::class);
|
|
||||||
$this->findViableNodesService = m::mock(FindViableNodesService::class);
|
$this->findViableNodesService = m::mock(FindViableNodesService::class);
|
||||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
|
||||||
$this->serverVariableRepository = m::mock(ServerVariableRepositoryInterface::class);
|
|
||||||
$this->userRepository = m::mock(UserRepositoryInterface::class);
|
|
||||||
$this->validatorService = m::mock(VariableValidatorService::class);
|
$this->validatorService = m::mock(VariableValidatorService::class);
|
||||||
|
$this->eggRepository = m::mock(EggRepository::class);
|
||||||
|
$this->repository = m::mock(ServerRepository::class);
|
||||||
|
$this->serverVariableRepository = m::mock(ServerVariableRepository::class);
|
||||||
|
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
|
||||||
|
$this->serverDeletionService = m::mock(ServerDeletionService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,7 +151,7 @@ class ServerCreationServiceTest extends TestCase
|
||||||
$this->configurationStructureService->shouldReceive('handle')->with($model)->once()->andReturn(['test' => 'struct']);
|
$this->configurationStructureService->shouldReceive('handle')->with($model)->once()->andReturn(['test' => 'struct']);
|
||||||
|
|
||||||
$this->daemonServerRepository->shouldReceive('setServer')->with($model)->once()->andReturnSelf();
|
$this->daemonServerRepository->shouldReceive('setServer')->with($model)->once()->andReturnSelf();
|
||||||
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'], ['start_on_completion' => false])->once();
|
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'])->once();
|
||||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||||
|
|
||||||
$response = $this->getService()->handle($model->toArray());
|
$response = $this->getService()->handle($model->toArray());
|
||||||
|
@ -250,12 +253,10 @@ class ServerCreationServiceTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test handling of node timeout or other daemon error.
|
* Test handling of node timeout or other daemon error.
|
||||||
*
|
|
||||||
* @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
*/
|
*/
|
||||||
public function testExceptionShouldBeThrownIfTheRequestFails()
|
public function testExceptionShouldBeThrownIfTheRequestFails()
|
||||||
{
|
{
|
||||||
$this->configureExceptionMock();
|
$this->expectException(DaemonConnectionException::class);
|
||||||
|
|
||||||
$model = factory(Server::class)->make([
|
$model = factory(Server::class)->make([
|
||||||
'uuid' => $this->getKnownUuid(),
|
'uuid' => $this->getKnownUuid(),
|
||||||
|
@ -269,8 +270,16 @@ class ServerCreationServiceTest extends TestCase
|
||||||
$this->validatorService->shouldReceive('handle')->once()->andReturn(collect([]));
|
$this->validatorService->shouldReceive('handle')->once()->andReturn(collect([]));
|
||||||
$this->configurationStructureService->shouldReceive('handle')->once()->andReturn([]);
|
$this->configurationStructureService->shouldReceive('handle')->once()->andReturn([]);
|
||||||
|
|
||||||
$this->daemonServerRepository->shouldReceive('setServer')->with($model)->once()->andThrow($this->getExceptionMock());
|
$this->connection->expects('commit')->withNoArgs();
|
||||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
|
||||||
|
$this->daemonServerRepository->shouldReceive('setServer')->with($model)->once()->andThrow(
|
||||||
|
new DaemonConnectionException(
|
||||||
|
new ConnectException('', new Request('GET', 'test'))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->serverDeletionService->expects('withForce')->with(true)->andReturnSelf();
|
||||||
|
$this->serverDeletionService->expects('handle')->with($model);
|
||||||
|
|
||||||
$this->getService()->handle($model->toArray());
|
$this->getService()->handle($model->toArray());
|
||||||
}
|
}
|
||||||
|
@ -290,6 +299,7 @@ class ServerCreationServiceTest extends TestCase
|
||||||
$this->eggRepository,
|
$this->eggRepository,
|
||||||
$this->findViableNodesService,
|
$this->findViableNodesService,
|
||||||
$this->configurationStructureService,
|
$this->configurationStructureService,
|
||||||
|
$this->serverDeletionService,
|
||||||
$this->repository,
|
$this->repository,
|
||||||
$this->serverVariableRepository,
|
$this->serverVariableRepository,
|
||||||
$this->validatorService
|
$this->validatorService
|
||||||
|
|
Loading…
Reference in a new issue