Update DockerTest.php

This commit is contained in:
Bozhidar 2024-04-30 00:07:17 +03:00
parent aa48915b05
commit 8dc9b2537b

View file

@ -5,6 +5,7 @@ namespace tests\Unit;
use App\Models\User; use App\Models\User;
use Livewire\Livewire; use Livewire\Livewire;
use Modules\Docker\Filament\Clusters\Docker\Pages\DockerCatalog; use Modules\Docker\Filament\Clusters\Docker\Pages\DockerCatalog;
use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource;
use Modules\Docker\PostInstall; use Modules\Docker\PostInstall;
use Tests\TestCase; use Tests\TestCase;
@ -29,9 +30,11 @@ class DockerTest extends TestCase
$this->actingAs(User::factory()->create()); $this->actingAs(User::factory()->create());
$livewireCatalogIndex = Livewire::test(DockerCatalog::class) $dockerImage = 'nginx';
->set('keyword', 'nginx')
->assertSee('nginx'); $dockerCatalogTest = Livewire::test(DockerCatalog::class);
$livewireCatalogIndex = $dockerCatalogTest->set('keyword', $dockerImage)
->assertSee($dockerImage);
$viewData = $livewireCatalogIndex->viewData('dockerImages'); $viewData = $livewireCatalogIndex->viewData('dockerImages');
$this->assertNotEmpty($viewData); $this->assertNotEmpty($viewData);
@ -39,6 +42,24 @@ class DockerTest extends TestCase
$livewireCatalogIndex->set('keyword', 'non-existing-image') $livewireCatalogIndex->set('keyword', 'non-existing-image')
->assertDontSee('non-existing-image'); ->assertDontSee('non-existing-image');
$pullDockerImage = $dockerCatalogTest->call('pullDockerImage', $dockerImage)
->assertSee('Pull Docker Image');
$isDokerImagePulled = false;
$pullLog = '';
for ($i = 0; $i < 300; $i++) {
$pullLog = @file_get_contents($pullDockerImage->get('pullLogFile'));
if (strpos($pullLog, 'DONE!') !== false) {
$isDokerImagePulled = true;
break;
}
sleep(1);
}
$this->assertTrue($isDokerImagePulled);
$this->assertNotEmpty($pullLog);
$this->assertStringContainsString('DONE!', $pullLog);
} }
} }