Files
keystone/tests/Feature/Drivers/Valkey8DriverTest.php
Harry Bayliss 66f0ee9e50
All checks were successful
CI / Tests (push) Successful in 43s
CI / Lint (push) Successful in 1m3s
Migrate to Gitea, switch JS tooling to oxlint/oxfmt, lift test coverage to 95%
- Add .gitea/workflows/ci.yml ported from lifeos (lint + tests with coverage gate)
- Set up phpstan (larastan + peststan, baseline at level max)
- Replace eslint/prettier with oxlint/oxfmt; reformat resources/
- Add composer phpstan/coverage/quality scripts; restore --min=95 coverage gate
- Exclude integration plumbing (Saloon Hetzner classes, SSH wrappers, console
  commands, DTOs) from coverage to keep the gate focused on business logic
- Add ~12 new test files covering models, drivers, controllers, jobs, auth
  flows, request validators, and the IP CIDR helper
- Fix Support\Ip::inNetwork PHP 8.4 TypeError in CIDR mask check
- Fix FirewallRule::command comparing the enum-cast type column to a string
- Fix Server::network using the wrong foreign key column
- Remove unreachable code under abort(403) in RegisteredUserController
2026-05-13 16:51:07 +01:00

111 lines
4.2 KiB
PHP

<?php
use App\Drivers\Valkey\Valkey8Driver;
use App\Enums\EnvironmentAttachmentRole;
use App\Enums\ServiceType;
use App\Models\Service;
use App\Models\ServiceSlice;
it('returns a two-step operation plan', function () {
$service = new Service(['id' => 7]);
$plan = (new Valkey8Driver(service: $service))->getOperationPlan('hash');
expect($plan->steps)->toHaveCount(2);
expect($plan->steps[0]->name)->toBe('Render Compose file');
expect($plan->steps[1]->getScript())->toContain('compose -f /home/keystone/services/7/compose.yml');
});
it('reports static metadata about the valkey driver', function () {
$driver = new Valkey8Driver;
expect($driver->serviceType())->toBe(ServiceType::VALKEY);
expect($driver->versionTrack())->toBe('8');
expect($driver->defaultImage())->toBe('valkey/valkey:8');
expect($driver->defaultPorts())->toBe([6379]);
expect($driver->firewallRules())->toBe(['6379/tcp']);
expect($driver->environmentSchema())->toBe([]);
expect($driver->resourceDefaults())->toBe([]);
expect($driver->updateBehavior())->toBe('stateful_downtime');
expect($driver->supportedSliceTypes())->toBe(['logical_database']);
expect($driver->environmentExports())->toBe([]);
});
it('exports redis env vars for a slice and adapts to the attachment role', function () {
$service = new Service(['id' => 3, 'name' => 'cache']);
$slice = new ServiceSlice([
'service_id' => 3,
'config' => ['host' => 'valkey-host', 'port' => 7000, 'database' => 2],
]);
$slice->setRelation('service', $service);
$driver = new Valkey8Driver(service: $service);
$base = $driver->environmentExportsForSlice($slice);
expect($base)->toMatchArray([
'REDIS_HOST' => 'valkey-host',
'REDIS_PORT' => '7000',
'REDIS_DB' => '2',
]);
expect($driver->environmentExportsForSlice($slice, EnvironmentAttachmentRole::CACHE))
->toHaveKey('CACHE_STORE', 'redis');
expect($driver->environmentExportsForSlice($slice, EnvironmentAttachmentRole::QUEUE))
->toHaveKey('QUEUE_CONNECTION', 'redis');
expect($driver->environmentExportsForSlice($slice, EnvironmentAttachmentRole::DATABASE))
->not->toHaveKey('CACHE_STORE');
});
it('uses defaults when slice config is missing', function () {
$service = new Service(['id' => 3]);
$slice = new ServiceSlice(['service_id' => 3, 'config' => []]);
$driver = new Valkey8Driver(service: $service);
expect($driver->environmentExportsForSlice($slice))->toBe([
'REDIS_HOST' => 'keystone-service-3',
'REDIS_PORT' => '6379',
'REDIS_DB' => '0',
]);
});
it('builds a slice provision script using the service slug', function () {
$service = new Service(['id' => 9, 'name' => 'My Cache']);
$slice = new ServiceSlice(['service_id' => 9, 'config' => ['database' => 4]]);
$slice->setRelation('service', $service);
$driver = new Valkey8Driver(service: $service);
$script = $driver->provisionSliceScript($slice);
expect($script)->toContain('docker compose -f /home/keystone/services/9/compose.yml exec -T my_cache valkey-cli');
expect($script)->toContain("-n '4' PING");
});
it('renders a compose service without persistence by default', function () {
$service = new Service(['id' => 1, 'config' => []]);
$compose = (new Valkey8Driver(service: $service))->composeService();
expect($compose['image'])->toBe('valkey/valkey:8');
expect($compose)->not->toHaveKey('volumes');
expect($compose)->not->toHaveKey('command');
});
it('renders a compose service with persistence enabled', function () {
$service = new Service(['id' => 1, 'config' => ['persistence' => true]]);
$driver = new Valkey8Driver(service: $service);
$compose = $driver->composeService();
expect($compose['volumes'])->toBe(['keystone_service_1_valkey_data:/data']);
expect($compose['command'])->toBe(['valkey-server', '--appendonly', 'yes']);
expect($driver->composeVolumes())->toBe(['keystone_service_1_valkey_data' => null]);
});
it('returns no compose volumes without persistence', function () {
$service = new Service(['id' => 1, 'config' => []]);
expect((new Valkey8Driver(service: $service))->composeVolumes())->toBe([]);
});