fix: DockerSecretsResolver - don't normalize absolute paths like /var/www/html/...
Some checks failed
Deploy Application / deploy (push) Has been cancelled
Some checks failed
Deploy Application / deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Framework\Discovery\Storage\ValueObjects;
|
||||
|
||||
use App\Framework\Core\ValueObjects\Timestamp;
|
||||
use App\Framework\Discovery\Results\AttributeRegistry;
|
||||
use App\Framework\Discovery\Results\DiscoveryRegistry;
|
||||
use App\Framework\Discovery\Results\InterfaceRegistry;
|
||||
use App\Framework\Discovery\Results\TemplateRegistry;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\CacheEntry;
|
||||
use App\Framework\Discovery\ValueObjects\CacheLevel;
|
||||
use App\Framework\Discovery\ValueObjects\CacheTier;
|
||||
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
describe('CacheEntry', function () {
|
||||
it('creates entry with DiscoveryRegistry', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$createdAt = Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00'));
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: $createdAt,
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
expect($entry->registry)->toBe($registry);
|
||||
expect($entry->createdAt)->toBe($createdAt);
|
||||
expect($entry->version)->toBe('v1-abc12345');
|
||||
expect($entry->cacheLevel)->toBe(CacheLevel::NORMAL);
|
||||
expect($entry->cacheTier)->toBe(CacheTier::HOT);
|
||||
expect($entry->isCompressed())->toBeFalse();
|
||||
});
|
||||
|
||||
it('creates entry with compressed array', function () {
|
||||
$compressedData = ['__discovery_compressed__' => true, 'data' => 'compressed'];
|
||||
|
||||
$createdAt = new \DateTimeImmutable('2024-01-01 12:00:00');
|
||||
$entry = new CacheEntry(
|
||||
registry: $compressedData,
|
||||
createdAt: $createdAt,
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::EXTENDED,
|
||||
cacheTier: CacheTier::ARCHIVE
|
||||
);
|
||||
|
||||
expect($entry->isCompressed())->toBeTrue();
|
||||
expect($entry->registry)->toBe($compressedData);
|
||||
});
|
||||
|
||||
it('creates from array', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$createdAt = Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00'));
|
||||
$data = [
|
||||
'registry' => $registry,
|
||||
'startTime' => $createdAt->toTimestamp(),
|
||||
'version' => 'v1-abc12345',
|
||||
'cacheLevel' => CacheLevel::NORMAL->value,
|
||||
'cacheTier' => CacheTier::HOT->value,
|
||||
];
|
||||
|
||||
$entry = CacheEntry::fromArray($data);
|
||||
|
||||
expect($entry->registry)->toBe($registry);
|
||||
expect($entry->createdAt->toTimestamp())->toBe($createdAt->toTimestamp());
|
||||
expect($entry->version)->toBe('v1-abc12345');
|
||||
expect($entry->cacheLevel)->toBe(CacheLevel::NORMAL);
|
||||
expect($entry->cacheTier)->toBe(CacheTier::HOT);
|
||||
});
|
||||
|
||||
it('converts to array', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$createdAt = Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00'));
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: $createdAt,
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$array = $entry->toArray();
|
||||
|
||||
expect($array)->toBeArray();
|
||||
expect($array['registry'])->toBe($registry);
|
||||
expect($array['startTime'])->toBe($createdAt->toTimestamp());
|
||||
expect($array['version'])->toBe('v1-abc12345');
|
||||
expect($array['cacheLevel'])->toBe(CacheLevel::NORMAL->value);
|
||||
expect($array['cacheTier'])->toBe(CacheTier::HOT->value);
|
||||
});
|
||||
|
||||
it('throws exception when getting registry from compressed entry', function () {
|
||||
$compressedData = ['__discovery_compressed__' => true, 'data' => 'compressed'];
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $compressedData,
|
||||
createdAt: Timestamp::now(),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
expect(fn() => $entry->getRegistry())->toThrow(\RuntimeException::class);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Framework\Discovery\Storage\ValueObjects;
|
||||
|
||||
use App\Framework\Discovery\Results\DiscoveryRegistry;
|
||||
use App\Framework\Discovery\Results\AttributeRegistry;
|
||||
use App\Framework\Discovery\Results\InterfaceRegistry;
|
||||
use App\Framework\Discovery\Results\TemplateRegistry;
|
||||
use App\Framework\Core\ValueObjects\Timestamp;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\CacheEntry;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\CacheRetrievalResult;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\StalenessCheckResult;
|
||||
use App\Framework\Discovery\ValueObjects\CacheLevel;
|
||||
use App\Framework\Discovery\ValueObjects\CacheTier;
|
||||
|
||||
describe('CacheRetrievalResult', function () {
|
||||
it('creates found result', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$result = CacheRetrievalResult::found($entry);
|
||||
|
||||
expect($result->found)->toBeTrue();
|
||||
expect($result->entry)->toBe($entry);
|
||||
expect($result->reason)->toBeNull();
|
||||
expect($result->isUsable())->toBeTrue();
|
||||
});
|
||||
|
||||
it('creates found result with staleness check', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$stalenessCheck = StalenessCheckResult::fresh();
|
||||
$result = CacheRetrievalResult::found($entry, $stalenessCheck);
|
||||
|
||||
expect($result->found)->toBeTrue();
|
||||
expect($result->stalenessCheck)->toBe($stalenessCheck);
|
||||
expect($result->isUsable())->toBeTrue();
|
||||
});
|
||||
|
||||
it('creates not found result', function () {
|
||||
$result = CacheRetrievalResult::notFound('not_found');
|
||||
|
||||
expect($result->found)->toBeFalse();
|
||||
expect($result->entry)->toBeNull();
|
||||
expect($result->reason)->toBe('not_found');
|
||||
expect($result->isUsable())->toBeFalse();
|
||||
});
|
||||
|
||||
it('creates stale result', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$stalenessCheck = StalenessCheckResult::stale('directory_modified');
|
||||
$result = CacheRetrievalResult::stale($entry, $stalenessCheck);
|
||||
|
||||
expect($result->found)->toBeTrue();
|
||||
expect($result->entry)->toBe($entry);
|
||||
expect($result->reason)->toBe('stale');
|
||||
expect($result->stalenessCheck)->toBe($stalenessCheck);
|
||||
expect($result->isUsable())->toBeFalse();
|
||||
});
|
||||
|
||||
it('throws exception when found without entry', function () {
|
||||
expect(fn() => new CacheRetrievalResult(
|
||||
found: true,
|
||||
entry: null
|
||||
))->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
|
||||
it('throws exception when not found with entry', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
expect(fn() => new CacheRetrievalResult(
|
||||
found: false,
|
||||
entry: $entry
|
||||
))->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Framework\Discovery\Storage\ValueObjects;
|
||||
|
||||
use App\Framework\Discovery\Storage\ValueObjects\StalenessCheckResult;
|
||||
|
||||
describe('StalenessCheckResult', function () {
|
||||
it('creates fresh result', function () {
|
||||
$result = StalenessCheckResult::fresh();
|
||||
|
||||
expect($result->isStale)->toBeFalse();
|
||||
expect($result->isFresh())->toBeTrue();
|
||||
expect($result->reason)->toBeNull();
|
||||
expect($result->modifiedPaths)->toBe([]);
|
||||
});
|
||||
|
||||
it('creates stale result with reason', function () {
|
||||
$result = StalenessCheckResult::stale('directory_modified', ['/path/to/src']);
|
||||
|
||||
expect($result->isStale)->toBeTrue();
|
||||
expect($result->isFresh())->toBeFalse();
|
||||
expect($result->reason)->toBe('directory_modified');
|
||||
expect($result->modifiedPaths)->toBe(['/path/to/src']);
|
||||
});
|
||||
|
||||
it('creates stale result without paths', function () {
|
||||
$result = StalenessCheckResult::stale('incremental_scan');
|
||||
|
||||
expect($result->isStale)->toBeTrue();
|
||||
expect($result->reason)->toBe('incremental_scan');
|
||||
expect($result->modifiedPaths)->toBe([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user