Remove DaemonConnectionException (#885)

* remove DaemonConnectionException

* update tests
This commit is contained in:
Boy132
2025-01-07 22:58:04 +01:00
committed by GitHub
parent 6fcf4173d3
commit c93a836ad8
33 changed files with 237 additions and 484 deletions

View File

@@ -10,8 +10,8 @@ use App\Models\Server;
use App\Models\Permission;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use App\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
use Illuminate\Http\Client\ConnectionException;
use Symfony\Component\HttpKernel\Exception\HttpException;
class CommandControllerTest extends ClientApiIntegrationTestCase
@@ -77,11 +77,7 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
[$user, $server] = $this->generateTestAccount();
$server = \Mockery::mock($server)->makePartial();
$server->expects('send')->andThrows(
new DaemonConnectionException(
new BadResponseException('', new Request('GET', 'test'), new GuzzleResponse(Response::HTTP_BAD_GATEWAY))
)
);
$server->expects('send')->andThrows(new ConnectionException(previous: new BadResponseException('', new Request('GET', 'test'), new GuzzleResponse(Response::HTTP_BAD_GATEWAY))));
$this->instance(Server::class, $server);

View File

@@ -5,17 +5,14 @@ namespace App\Tests\Integration\Jobs\Schedule;
use App\Enums\ServerState;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use GuzzleHttp\Psr7\Request;
use App\Models\Task;
use GuzzleHttp\Psr7\Response;
use App\Models\Server;
use App\Models\Schedule;
use Illuminate\Support\Facades\Bus;
use App\Jobs\Schedule\RunTaskJob;
use GuzzleHttp\Exception\BadResponseException;
use App\Tests\Integration\IntegrationTestCase;
use App\Repositories\Daemon\DaemonPowerRepository;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Illuminate\Http\Client\ConnectionException;
class RunTaskJobTest extends IntegrationTestCase
{
@@ -126,12 +123,10 @@ class RunTaskJobTest extends IntegrationTestCase
$mock = \Mockery::mock(DaemonPowerRepository::class);
$this->instance(DaemonPowerRepository::class, $mock);
$mock->expects('setServer->send')->andThrow(
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response()))
);
$mock->expects('setServer->send')->andThrow(new ConnectionException());
if (!$continueOnFailure) {
$this->expectException(DaemonConnectionException::class);
$this->expectException(ConnectionException::class);
}
Bus::dispatchSync(new RunTaskJob($task));

View File

@@ -12,7 +12,7 @@ use App\Services\Backups\DeleteBackupService;
use App\Tests\Integration\IntegrationTestCase;
use App\Repositories\Daemon\DaemonBackupRepository;
use App\Exceptions\Service\Backup\BackupLockedException;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Illuminate\Http\Client\ConnectionException;
class DeleteBackupServiceTest extends IntegrationTestCase
{
@@ -54,11 +54,7 @@ class DeleteBackupServiceTest extends IntegrationTestCase
$backup = Backup::factory()->create(['server_id' => $server->id]);
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andThrow(
new DaemonConnectionException(
new ClientException('', new Request('DELETE', '/'), new Response(404))
)
);
$mock->expects('setServer->delete')->with($backup)->andThrow(new ConnectionException(previous: new ClientException('', new Request('DELETE', '/'), new Response(404))));
$this->app->make(DeleteBackupService::class)->handle($backup);
@@ -73,13 +69,9 @@ class DeleteBackupServiceTest extends IntegrationTestCase
$backup = Backup::factory()->create(['server_id' => $server->id]);
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andThrow(
new DaemonConnectionException(
new ClientException('', new Request('DELETE', '/'), new Response(500))
)
);
$mock->expects('setServer->delete')->with($backup)->andThrow(new ConnectionException(previous: new ClientException('', new Request('DELETE', '/'), new Response(500))));
$this->expectException(DaemonConnectionException::class);
$this->expectException(ConnectionException::class);
$this->app->make(DeleteBackupService::class)->handle($backup);

View File

@@ -3,16 +3,13 @@
namespace App\Tests\Integration\Services\Servers;
use Mockery\MockInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use App\Models\Server;
use App\Models\Allocation;
use GuzzleHttp\Exception\RequestException;
use App\Exceptions\DisplayException;
use App\Tests\Integration\IntegrationTestCase;
use App\Repositories\Daemon\DaemonServerRepository;
use App\Services\Servers\BuildModificationService;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Illuminate\Http\Client\ConnectionException;
class BuildModificationServiceTest extends IntegrationTestCase
{
@@ -149,11 +146,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$this->daemonServerRepository->expects('setServer->sync')->andThrows(
new DaemonConnectionException(
new RequestException('Bad request', new Request('GET', '/test'), new Response())
)
);
$this->daemonServerRepository->expects('setServer->sync')->andThrows(new ConnectionException());
$response = $this->getService()->handle($server, ['memory' => 256, 'disk' => 10240]);

View File

@@ -3,16 +3,13 @@
namespace App\Tests\Integration\Services\Servers;
use Mockery\MockInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use App\Models\Database;
use App\Models\DatabaseHost;
use GuzzleHttp\Exception\BadResponseException;
use App\Tests\Integration\IntegrationTestCase;
use App\Services\Servers\ServerDeletionService;
use App\Repositories\Daemon\DaemonServerRepository;
use App\Services\Databases\DatabaseManagementService;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Illuminate\Http\Client\ConnectionException;
class ServerDeletionServiceTest extends IntegrationTestCase
{
@@ -59,11 +56,9 @@ class ServerDeletionServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->expectException(DaemonConnectionException::class);
$this->expectException(ConnectionException::class);
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response()))
);
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(new ConnectionException());
$this->getService()->handle($server);
@@ -77,9 +72,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response(404)))
);
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(new ConnectionException(code: 404));
$this->getService()->handle($server);
@@ -94,9 +87,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response(500)))
);
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(new ConnectionException());
$this->getService()->withForce()->handle($server);