Add build modification settings, fix exception handling to log to file

This commit is contained in:
Dane Everitt 2017-07-23 19:57:43 -05:00
parent ace70a3599
commit f842aae3d3
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
15 changed files with 427 additions and 50 deletions

View file

@ -26,6 +26,7 @@ namespace Tests\Unit\Services\Servers;
use Exception;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Log\Writer;
use Mockery as m;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Models\Server;
@ -61,6 +62,11 @@ class ContainerRebuildServiceTest extends TestCase
*/
protected $service;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
/**
* Setup tests.
*/
@ -71,9 +77,15 @@ class ContainerRebuildServiceTest extends TestCase
$this->daemonServerRepository = m::mock(DaemonServerRepositoryInterface::class);
$this->exception = m::mock(RequestException::class)->makePartial();
$this->repository = m::mock(ServerRepositoryInterface::class);
$this->writer = m::mock(Writer::class);
$this->server = factory(Server::class)->make(['node_id' => 1]);
$this->service = new ContainerRebuildService($this->daemonServerRepository, $this->repository);
$this->service = new ContainerRebuildService(
$this->daemonServerRepository,
$this->repository,
$this->writer
);
}
/**
@ -114,6 +126,8 @@ class ContainerRebuildServiceTest extends TestCase
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
try {
$this->service->rebuild($this->server);
} catch (Exception $exception) {

View file

@ -24,6 +24,7 @@
namespace Tests\Unit\Services\Servers;
use Illuminate\Log\Writer;
use Mockery as m;
use phpmock\phpunit\PHPMock;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
@ -98,6 +99,11 @@ class CreationServiceTest extends TestCase
*/
protected $uuid;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
/**
* Setup tests.
*/
@ -115,6 +121,7 @@ class CreationServiceTest extends TestCase
$this->usernameService = m::mock(UsernameGenerationService::class);
$this->validatorService = m::mock(VariableValidatorService::class);
$this->uuid = m::mock('overload:Ramsey\Uuid\Uuid');
$this->writer = m::mock(Writer::class);
$this->getFunctionMock('\\Pterodactyl\\Services\\Servers', 'bin2hex')
->expects($this->any())->willReturn('randomstring');
@ -131,7 +138,8 @@ class CreationServiceTest extends TestCase
$this->serverVariableRepository,
$this->userRepository,
$this->usernameService,
$this->validatorService
$this->validatorService,
$this->writer
);
}

View file

@ -25,6 +25,7 @@
namespace Tests\Unit\Services\Servers;
use Exception;
use Illuminate\Log\Writer;
use Mockery as m;
use Tests\TestCase;
use phpmock\phpunit\PHPMock;
@ -65,6 +66,11 @@ class DetailsModificationServiceTest extends TestCase
*/
protected $service;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
/**
* Setup tests.
*/
@ -76,6 +82,7 @@ class DetailsModificationServiceTest extends TestCase
$this->exception = m::mock(RequestException::class)->makePartial();
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
$this->repository = m::mock(ServerRepository::class);
$this->writer = m::mock(Writer::class);
$this->getFunctionMock('\\Pterodactyl\\Services\\Servers', 'bin2hex')
->expects($this->any())->willReturn('randomString');
@ -83,7 +90,8 @@ class DetailsModificationServiceTest extends TestCase
$this->service = new DetailsModificationService(
$this->database,
$this->daemonServerRepository,
$this->repository
$this->repository,
$this->writer
);
}
@ -243,7 +251,7 @@ class DetailsModificationServiceTest extends TestCase
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
$this->database->shouldNotReceive('commit');
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
try {
$this->service->edit($server, $data);
@ -281,7 +289,6 @@ class DetailsModificationServiceTest extends TestCase
], true, true)->once()->andReturnNull();
$this->daemonServerRepository->shouldReceive('setNode')->andThrow(new Exception());
$this->database->shouldNotReceive('commit');
$this->service->edit($server, $data);
}
@ -357,7 +364,7 @@ class DetailsModificationServiceTest extends TestCase
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
$this->database->shouldNotReceive('commit');
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
try {
$this->service->setDockerImage($server, 'new/image');
@ -385,7 +392,6 @@ class DetailsModificationServiceTest extends TestCase
])->once()->andReturnNull();
$this->daemonServerRepository->shouldReceive('setNode')->andThrow(new Exception());
$this->database->shouldNotReceive('commit');
$this->service->setDockerImage($server, 'new/image');
}

View file

@ -27,6 +27,7 @@ namespace Tests\Unit\Services\Servers;
use Exception;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Log\Writer;
use Mockery as m;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Models\Server;
@ -67,6 +68,11 @@ class ReinstallServiceTest extends TestCase
*/
protected $service;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
/**
* Setup tests.
*/
@ -78,12 +84,15 @@ class ReinstallServiceTest extends TestCase
$this->database = m::mock(ConnectionInterface::class);
$this->exception = m::mock(RequestException::class)->makePartial();
$this->repository = m::mock(ServerRepositoryInterface::class);
$this->writer = m::mock(Writer::class);
$this->server = factory(Server::class)->make(['node_id' => 1]);
$this->service = new ReinstallService(
$this->database,
$this->daemonServerRepository,
$this->repository
$this->repository,
$this->writer
);
}
@ -146,6 +155,8 @@ class ReinstallServiceTest extends TestCase
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
try {
$this->service->reinstall($this->server);
} catch (Exception $exception) {

View file

@ -27,6 +27,7 @@ namespace Tests\Unit\Services\Servers;
use Exception;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Log\Writer;
use Mockery as m;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
@ -67,6 +68,11 @@ class SuspensionServiceTest extends TestCase
*/
protected $service;
/**
* @var \Illuminate\Log\Writer
*/
protected $writer;
/**
* Setup tests.
*/
@ -78,13 +84,15 @@ class SuspensionServiceTest extends TestCase
$this->database = m::mock(ConnectionInterface::class);
$this->exception = m::mock(RequestException::class)->makePartial();
$this->repository = m::mock(ServerRepositoryInterface::class);
$this->writer = m::mock(Writer::class);
$this->server = factory(Server::class)->make(['suspended' => 0, 'node_id' => 1]);
$this->service = new SuspensionService(
$this->database,
$this->daemonServerRepository,
$this->repository
$this->repository,
$this->writer
);
}
@ -176,6 +184,8 @@ class SuspensionServiceTest extends TestCase
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
try {
$this->service->toggle($this->server);
} catch (Exception $exception) {