2024-04-29 16:27:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace tests\Unit;
|
|
|
|
|
2024-04-29 22:10:08 +00:00
|
|
|
use App\Filament\Pages\Modules;
|
2024-04-29 22:15:46 +00:00
|
|
|
use App\Models\Module;
|
2024-04-29 17:06:33 +00:00
|
|
|
use App\Models\User;
|
2024-04-29 21:43:30 +00:00
|
|
|
use Filament\Actions\DeleteAction;
|
2024-04-29 17:06:33 +00:00
|
|
|
use Livewire\Livewire;
|
2024-04-29 21:43:30 +00:00
|
|
|
use Modules\Docker\App\Models\DockerContainer;
|
2024-04-29 17:06:33 +00:00
|
|
|
use Modules\Docker\Filament\Clusters\Docker\Pages\DockerCatalog;
|
2024-04-29 21:43:30 +00:00
|
|
|
use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pages\CreateDockerContainer;
|
|
|
|
use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pages\EditDockerContainer;
|
|
|
|
use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pages\ListDockerContainers;
|
2024-04-29 17:06:33 +00:00
|
|
|
use Modules\Docker\PostInstall;
|
2024-04-30 08:34:17 +00:00
|
|
|
use Psy\Util\Str;
|
2024-04-29 17:06:33 +00:00
|
|
|
use Tests\TestCase;
|
2024-04-29 16:27:27 +00:00
|
|
|
|
2024-04-29 17:06:33 +00:00
|
|
|
class DockerTest extends TestCase
|
2024-04-29 16:27:27 +00:00
|
|
|
{
|
2024-04-29 21:43:30 +00:00
|
|
|
public function testDockerImages()
|
2024-04-29 16:27:27 +00:00
|
|
|
{
|
2024-04-30 08:59:26 +00:00
|
|
|
// ini_set('memory_limit', '-1');
|
|
|
|
// ini_set('max_execution_time', 0);
|
|
|
|
//
|
|
|
|
// $this->actingAs(User::factory()->create());
|
|
|
|
// if (!is_file('/usr/local/phyre/web/storage/installed')) {
|
|
|
|
// file_put_contents('/usr/local/phyre/web/storage/installed', '');
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $modulesTest = Livewire::test(Modules::class);
|
|
|
|
// $modulesTest->call('openInstallModal', 'Docker');
|
|
|
|
//
|
|
|
|
// $installLogFilePath = $modulesTest->get('installLogFilePath');
|
|
|
|
//
|
|
|
|
// $dockerIsInstalled = false;
|
|
|
|
// for ($i = 0; $i < 400; $i++) {
|
|
|
|
// $modulesTest->call('getInstallLog');
|
|
|
|
// $logFile = file_get_contents($installLogFilePath);
|
|
|
|
// if (strpos($logFile, 'Done!') !== false) {
|
|
|
|
// $dockerIsInstalled = true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// sleep(1);
|
|
|
|
// }
|
|
|
|
// $this->assertTrue($dockerIsInstalled);
|
|
|
|
//
|
|
|
|
// $findModule = Module::where('name', 'Docker')->first();
|
|
|
|
// $this->assertNotEmpty($findModule);
|
|
|
|
//
|
|
|
|
// $dockerImage = 'nginx';
|
|
|
|
//
|
|
|
|
// $dockerCatalogTest = Livewire::test(DockerCatalog::class);
|
|
|
|
// $livewireCatalogIndex = $dockerCatalogTest->set('keyword', $dockerImage)
|
|
|
|
// ->assertSee($dockerImage);
|
|
|
|
//
|
|
|
|
// $viewData = $livewireCatalogIndex->viewData('dockerImages');
|
|
|
|
// $this->assertNotEmpty($viewData);
|
|
|
|
//
|
|
|
|
// $livewireCatalogIndex->set('keyword', 'non-existing-image')
|
|
|
|
// ->assertDontSee('non-existing-image');
|
|
|
|
//
|
|
|
|
// $pullDockerImage = $dockerCatalogTest->call('pullDockerImage', $dockerImage)
|
|
|
|
// ->assertSee('Pull Docker Image');
|
|
|
|
//
|
|
|
|
// $pullLog = '';
|
|
|
|
// $isDockerImagePulled = false;
|
|
|
|
// for ($i = 0; $i < 300; $i++) {
|
|
|
|
// $pullLog = @file_get_contents($pullDockerImage->get('pullLogFile'));
|
|
|
|
// if (str_contains($pullLog, 'DONE!')) {
|
|
|
|
// $isDockerImagePulled = true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// sleep(1);
|
|
|
|
// }
|
|
|
|
// $this->assertTrue($isDockerImagePulled);
|
|
|
|
//
|
|
|
|
// $this->assertNotEmpty($pullLog);
|
|
|
|
// $this->assertStringContainsString('DONE!', $pullLog);
|
|
|
|
//
|
|
|
|
// $createDockerContainerTest = Livewire::test(CreateDockerContainer::class);
|
|
|
|
// $createDockerContainerTest->assertSee('Create Docker Container');
|
|
|
|
//
|
|
|
|
// $dockerName = \Illuminate\Support\Str::random(10);
|
|
|
|
// $create = $createDockerContainerTest->fillForm([
|
|
|
|
// 'name' => $dockerName,
|
|
|
|
// 'image' => 'nginx',
|
|
|
|
// 'environmentVariables' => [
|
|
|
|
// 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
|
|
|
// 'NGINX_VERSION' => '1.25.5',
|
|
|
|
// 'NJS_VERSION' => '0.8.4',
|
|
|
|
// 'NJS_RELEASE' => '2~bookworm',
|
|
|
|
// 'PKG_RELEASE' => '1~bookworm',
|
|
|
|
// ],
|
|
|
|
// 'volumeMapping' => [],
|
|
|
|
// 'port' => '83',
|
|
|
|
// 'externalPort' => '3000',
|
|
|
|
// ])->call('create');
|
|
|
|
//
|
|
|
|
// $this->assertDatabaseHas(DockerContainer::class, [
|
|
|
|
// 'name' => $dockerName,
|
|
|
|
// ]);
|
2024-04-30 08:51:35 +00:00
|
|
|
//
|
|
|
|
// $listDockerContainersTest = Livewire::test(ListDockerContainers::class);
|
|
|
|
// $listDockerContainersTest->assertSee($dockerName);
|
|
|
|
//
|
|
|
|
// $findDockerContainer = DockerContainer::where('name', $dockerName)->first();
|
|
|
|
//
|
|
|
|
// $editDockerContainersTest = Livewire::test(EditDockerContainer::class, [
|
|
|
|
// 'record'=> $findDockerContainer->id
|
|
|
|
// ]);
|
|
|
|
// $editDockerContainersTest->assertSee('Edit Docker Container');
|
|
|
|
// $editDockerContainersTest->callAction(DeleteAction::class);
|
|
|
|
//
|
|
|
|
// $this->assertModelMissing($findDockerContainer);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// // Unistall docker
|
|
|
|
// $modulesTest = Livewire::test(Modules::class);
|
|
|
|
// $modulesTest->call('openUnistallModal', 'Docker');
|
2024-04-29 21:43:30 +00:00
|
|
|
}
|
2024-04-29 16:27:27 +00:00
|
|
|
}
|