clusev/tests/Feature/CommandShortcutsTest.php

78 lines
3.4 KiB
PHP

<?php
namespace Tests\Feature;
use Tests\TestCase;
class CommandShortcutsTest extends TestCase
{
/** Files shown to the operator — none may print the long compose filename. */
private const DISPLAY_SURFACES = [
'resources/views/livewire/versions/index.blade.php',
'resources/views/livewire/help/content/de/recovery.blade.php',
'resources/views/livewire/help/content/en/recovery.blade.php',
'resources/views/livewire/help/content/de/updates.blade.php',
'resources/views/livewire/help/content/en/updates.blade.php',
'resources/views/livewire/help/content/de/commands.blade.php',
'resources/views/livewire/help/content/en/commands.blade.php',
'resources/views/livewire/help/content/de/domain-tls.blade.php',
'resources/views/livewire/help/content/en/domain-tls.blade.php',
'docker/motd/00-clusev',
];
/** Operator-facing files that must use the short `sudo clusev update`, never `sudo ./update.sh`. */
private const UPDATE_COMMAND_SURFACES = [
'resources/views/livewire/help/content/de/domain-tls.blade.php',
'resources/views/livewire/help/content/en/domain-tls.blade.php',
'resources/views/livewire/help/content/de/updates.blade.php',
'resources/views/livewire/help/content/en/updates.blade.php',
'lang/de/system.php',
'lang/en/system.php',
'lang/de/versions.php',
'lang/en/versions.php',
];
public function test_no_display_surface_leaks_the_long_compose_filename(): void
{
foreach (self::DISPLAY_SURFACES as $rel) {
$contents = file_get_contents(base_path($rel));
$this->assertNotFalse($contents, "Could not read {$rel}");
$this->assertStringNotContainsString('docker-compose.prod.yml', $contents, "{$rel} still shows docker-compose.prod.yml");
}
}
public function test_operator_update_instructions_use_the_short_command(): void
{
foreach (self::UPDATE_COMMAND_SURFACES as $rel) {
$contents = file_get_contents(base_path($rel));
$this->assertNotFalse($contents, "Could not read {$rel}");
$this->assertStringNotContainsString('sudo ./update.sh', $contents, "{$rel} still shows the long update command");
}
}
public function test_versions_panel_shows_the_short_update_command(): void
{
$blade = file_get_contents(base_path('resources/views/livewire/versions/index.blade.php'));
$this->assertStringContainsString('sudo clusev update', $blade);
$this->assertStringNotContainsString('docker compose -f', $blade);
}
public function test_reset_hints_use_the_short_host_command(): void
{
foreach (['de', 'en'] as $locale) {
$settings = require base_path("lang/{$locale}/settings.php");
$system = require base_path("lang/{$locale}/system.php");
$this->assertStringContainsString('clusev reset-admin', $settings['recovery_note']);
$this->assertStringContainsString('clusev reset-admin', $system['ssh_reset_hint']);
}
}
public function test_motd_uses_short_commands(): void
{
$motd = file_get_contents(base_path('docker/motd/00-clusev'));
$this->assertStringContainsString('clusev ps | logs | restart', $motd);
$this->assertStringContainsString('sudo clusev update', $motd);
$this->assertStringContainsString('clusev reset-admin', $motd);
}
}