diff --git a/web/tests/Unit/DockerTest.php b/web/tests/Unit/DockerTest.php index 2c95207..c18e75f 100644 --- a/web/tests/Unit/DockerTest.php +++ b/web/tests/Unit/DockerTest.php @@ -5,6 +5,7 @@ namespace tests\Unit; use App\Models\User; use Livewire\Livewire; use Modules\Docker\Filament\Clusters\Docker\Pages\DockerCatalog; +use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource; use Modules\Docker\PostInstall; use Tests\TestCase; @@ -29,9 +30,11 @@ class DockerTest extends TestCase $this->actingAs(User::factory()->create()); - $livewireCatalogIndex = Livewire::test(DockerCatalog::class) - ->set('keyword', 'nginx') - ->assertSee('nginx'); + $dockerImage = 'nginx'; + + $dockerCatalogTest = Livewire::test(DockerCatalog::class); + $livewireCatalogIndex = $dockerCatalogTest->set('keyword', $dockerImage) + ->assertSee($dockerImage); $viewData = $livewireCatalogIndex->viewData('dockerImages'); $this->assertNotEmpty($viewData); @@ -39,6 +42,24 @@ class DockerTest extends TestCase $livewireCatalogIndex->set('keyword', '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); + } }