Update some server service tests
This commit is contained in:
parent
83a59cdf4f
commit
b55767426f
6 changed files with 117 additions and 165 deletions
|
@ -40,53 +40,62 @@ class ServerConfigurationStructureServiceTest extends TestCase
|
|||
*/
|
||||
public function testCorrectStructureIsReturned()
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $model */
|
||||
$model = factory(Server::class)->make();
|
||||
$model->setRelation('pack', null);
|
||||
$model->setRelation('allocation', factory(Allocation::class)->make());
|
||||
$model->setRelation('allocations', collect(factory(Allocation::class)->times(2)->make()));
|
||||
$model->setRelation('egg', factory(Egg::class)->make());
|
||||
|
||||
$portListing = $model->allocations->groupBy('ip')->map(function ($item) {
|
||||
return $item->pluck('port');
|
||||
})->toArray();
|
||||
|
||||
$this->repository->shouldReceive('getDataForCreation')->with($model)->once()->andReturn($model);
|
||||
$this->environment->shouldReceive('handle')->with($model)->once()->andReturn(['environment_array']);
|
||||
$this->environment->expects('handle')->with($model)->andReturn(['environment_array']);
|
||||
|
||||
$response = $this->getService()->handle($model);
|
||||
$this->assertNotEmpty($response);
|
||||
$this->assertArrayNotHasKey('user', $response);
|
||||
$this->assertArrayNotHasKey('keys', $response);
|
||||
|
||||
$this->assertArrayHasKey('uuid', $response);
|
||||
$this->assertArrayHasKey('suspended', $response);
|
||||
$this->assertArrayHasKey('environment', $response);
|
||||
$this->assertArrayHasKey('invocation', $response);
|
||||
$this->assertArrayHasKey('build', $response);
|
||||
$this->assertArrayHasKey('service', $response);
|
||||
$this->assertArrayHasKey('rebuild', $response);
|
||||
$this->assertArrayHasKey('suspended', $response);
|
||||
$this->assertArrayHasKey('container', $response);
|
||||
$this->assertArrayHasKey('allocations', $response);
|
||||
|
||||
$this->assertArraySubset([
|
||||
$this->assertSame([
|
||||
'default' => [
|
||||
'ip' => $model->allocation->ip,
|
||||
'port' => $model->allocation->port,
|
||||
],
|
||||
], $response['build'], true, 'Assert server default allocation is correct.');
|
||||
$this->assertArraySubset(['ports' => $portListing], $response['build'], true, 'Assert server ports are correct.');
|
||||
$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.');
|
||||
'mappings' => $model->getAllocationMappings(),
|
||||
], $response['allocations']);
|
||||
|
||||
$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,
|
||||
'pack' => null,
|
||||
'skip_scripts' => $model->skip_scripts,
|
||||
], $response['service']);
|
||||
|
||||
$this->assertFalse($response['rebuild']);
|
||||
$this->assertSame((int) $model->suspended, $response['suspended']);
|
||||
$this->assertSame([
|
||||
'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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue