mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Enums\LoadBalancerMethod;
|
|
use App\Facades\SSH;
|
|
use App\Models\Server;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
use Tests\Traits\PrepareLoadBalancer;
|
|
|
|
class LoadBalancerTest extends TestCase
|
|
{
|
|
use PrepareLoadBalancer;
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->prepare();
|
|
}
|
|
|
|
public function test_update_load_balancer_servers(): void
|
|
{
|
|
SSH::fake();
|
|
|
|
$this->actingAs($this->user);
|
|
|
|
$servers = Server::query()->where('id', '!=', $this->server->id)->get();
|
|
$this->assertEquals(2, $servers->count());
|
|
|
|
$this->post(route('application.update-load-balancer', [
|
|
'server' => $this->server->id,
|
|
'site' => $this->site->id,
|
|
]), [
|
|
'method' => LoadBalancerMethod::ROUND_ROBIN,
|
|
'servers' => [
|
|
[
|
|
'ip' => $servers[0]->local_ip,
|
|
'port' => 80,
|
|
'weight' => 1,
|
|
'backup' => false,
|
|
],
|
|
[
|
|
'ip' => $servers[1]->local_ip,
|
|
'port' => 80,
|
|
'weight' => 1,
|
|
'backup' => false,
|
|
],
|
|
],
|
|
])
|
|
->assertSessionDoesntHaveErrors();
|
|
|
|
$this->assertDatabaseHas('load_balancer_servers', [
|
|
'load_balancer_id' => $this->site->id,
|
|
'ip' => $servers[0]->local_ip,
|
|
'port' => 80,
|
|
'weight' => 1,
|
|
'backup' => false,
|
|
]);
|
|
$this->assertDatabaseHas('load_balancer_servers', [
|
|
'load_balancer_id' => $this->site->id,
|
|
'ip' => $servers[1]->local_ip,
|
|
'port' => 80,
|
|
'weight' => 1,
|
|
'backup' => false,
|
|
]);
|
|
}
|
|
}
|