Add tests for new service

This commit is contained in:
Dane Everitt 2018-03-02 19:37:21 -06:00
parent bcb69603ad
commit e39353a18d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 256 additions and 20 deletions

View file

@ -21,6 +21,7 @@ class DeployServerDatabaseService
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
*/
private $managementService;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
@ -63,21 +64,23 @@ class DeployServerDatabaseService
}
$allowRandom = config('pterodactyl.client_features.databases.allow_random');
$host = $this->databaseHostRepository->setColumns(['id'])->findWhere([
$hosts = $this->databaseHostRepository->setColumns(['id'])->findWhere([
['node_id', '=', $server->node_id],
])->random();
]);
if (empty($host) && ! $allowRandom) {
if ($hosts->isEmpty() && ! $allowRandom) {
throw new NoSuitableDatabaseHostException;
}
if (empty($host)) {
$host = $this->databaseHostRepository->setColumns(['id'])->all()->random();
if (empty($host)) {
if ($hosts->isEmpty()) {
$hosts = $this->databaseHostRepository->setColumns(['id'])->all();
if ($hosts->isEmpty()) {
throw new NoSuitableDatabaseHostException;
}
}
$host = $hosts->random();
return $this->managementService->create($server->id, [
'database_host_id' => $host->id,
'database' => array_get($data, 'database'),