tests(integration): fix database services

This commit is contained in:
Matthew Penner 2021-03-05 09:15:23 -07:00
parent ffdf27e606
commit 350ef1aba5
3 changed files with 15 additions and 16 deletions

View file

@ -10,7 +10,6 @@ namespace Pterodactyl\Models;
* @property string $username
* @property string $password
* @property int|null $max_databases
* @property int|null $node_id
* @property \Carbon\CarbonImmutable $created_at
* @property \Carbon\CarbonImmutable $updated_at
*/

View file

@ -62,7 +62,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testDatabaseCannotBeCreatedIfServerHasReachedLimit()
{
$server = $this->createServerModel(['database_limit' => 2]);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create();
Database::factory()->times(2)->create(['server_id' => $server->id, 'database_host_id' => $host->id]);
@ -93,10 +93,10 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testCreatingDatabaseWithIdenticalNameTriggersAnException()
{
$server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id);
$name = DatabaseManagementService::generateUniqueDatabaseName('something', $server->id);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$host2 = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create();
$host2 = DatabaseHost::factory()->create();
Database::factory()->create([
'database' => $name,
'database_host_id' => $host->id,
@ -122,9 +122,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testServerDatabaseCanBeCreated()
{
$server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id);
$name = DatabaseManagementService::generateUniqueDatabaseName('something', $server->id);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create();
$this->repository->expects('createDatabase')->with($name);
@ -180,9 +180,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testExceptionEncounteredWhileCreatingDatabaseAttemptsToCleanup()
{
$server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id);
$name = DatabaseManagementService::generateUniqueDatabaseName('something', $server->id);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create();
$this->repository->expects('createDatabase')->with($name)->andThrows(new BadMethodCallException());
$this->repository->expects('dropDatabase')->with($name);

View file

@ -64,8 +64,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$node = Node::factory()->create(['location_id' => $server->location->id]);
DatabaseHost::factory()->create(['node_id' => $node->id]);
$host = DatabaseHost::factory()->create();
$node = Node::factory()->create(['location_id' => $server->location->id, 'database_host_id' => $host->id]);
config()->set('pterodactyl.client_features.databases.allow_random', false);
@ -99,9 +99,9 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$node = Node::factory()->create(['location_id' => $server->location->id]);
DatabaseHost::factory()->create(['node_id' => $node->id]);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$node = Node::factory()->create(['location_id' => $server->location->id, 'database_host_id' => DatabaseHost::factory()->create()->id]);
$host = DatabaseHost::factory()->create();
$server->node->database_host_id = $host->id;
$this->managementService->expects('create')->with($server, [
'database_host_id' => $host->id,
@ -126,8 +126,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$node = Node::factory()->create(['location_id' => $server->location->id]);
$host = DatabaseHost::factory()->create(['node_id' => $node->id]);
$host = DatabaseHost::factory()->create();
$node = Node::factory()->create(['location_id' => $server->location->id, 'database_host_id' => $host->id]);
$this->managementService->expects('create')->with($server, [
'database_host_id' => $host->id,