mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 13:34:04 +00:00
Refactor DeleteTenantStorage tests
Use the *original* 'tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage' test and remove what's not necessary anymore. Also make it clear that enabling FS bootstrapper is not required for the deletion to work -- the tenant directory just has to exist. Delete the nonsensical 'DeleteTenantStorage does not delete the central storage directory when the filesystem bootstrapper is disabled' test. That one was there to test that the central dir never gets deleted, but it was wrong. Added 'DeleteTenantStorage never deletes the central storage directory' which actually makes the job's realpath() comparison check pass and the job just returns.
This commit is contained in:
parent
45100453c5
commit
e6d785a8d1
1 changed files with 26 additions and 19 deletions
|
|
@ -185,7 +185,7 @@ test('create and delete storage symlinks jobs work', function() {
|
||||||
$this->assertDirectoryDoesNotExist(public_path("public-$tenantKey"));
|
$this->assertDirectoryDoesNotExist(public_path("public-$tenantKey"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage', function(bool $suffixStoragePath) {
|
test('tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage', function (bool $bootstrapperEnabled) {
|
||||||
Event::listen(DeletingTenant::class,
|
Event::listen(DeletingTenant::class,
|
||||||
JobPipeline::make([DeleteTenantStorage::class])->send(function (DeletingTenant $event) {
|
JobPipeline::make([DeleteTenantStorage::class])->send(function (DeletingTenant $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
|
|
@ -193,40 +193,47 @@ test('tenant storage gets deleted during tenant deletion when the DeletingTenant
|
||||||
);
|
);
|
||||||
|
|
||||||
config([
|
config([
|
||||||
'tenancy.bootstrappers' => [FilesystemTenancyBootstrapper::class],
|
'tenancy.bootstrappers' => $bootstrapperEnabled ? [FilesystemTenancyBootstrapper::class] : [],
|
||||||
// suffix_storage_path only affects the storage_path() helper.
|
|
||||||
// The disks are scoped to the tenant's storage directory either way,
|
|
||||||
// so the tenant files end up there.
|
|
||||||
'tenancy.filesystem.suffix_storage_path' => $suffixStoragePath,
|
|
||||||
// This is the default tenancy config -- set it here explicitly for clarity
|
|
||||||
'tenancy.filesystem.suffix_base' => 'tenant',
|
|
||||||
'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$centralStoragePath = storage_path();
|
$centralStoragePath = storage_path();
|
||||||
|
$tenantStoragePath = fn (Tenant $tenant) => $centralStoragePath . "/tenant{$tenant->getTenantKey()}";
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
$tenantStoragePath = $centralStoragePath . "/tenant{$tenant->getTenantKey()}";
|
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
File::ensureDirectoryExists($tenantStoragePath($tenant));
|
||||||
|
|
||||||
Storage::disk('public')->put('foo.txt', 'tenant file');
|
expect(File::isDirectory($centralStoragePath))->toBeTrue();
|
||||||
expect(file_get_contents($tenantStoragePath . '/app/public/foo.txt'))->toBe('tenant file');
|
expect(File::isDirectory($tenantStoragePath($tenant)))->toBeTrue();
|
||||||
|
|
||||||
$tenant->delete();
|
$tenant->delete();
|
||||||
|
|
||||||
expect(File::isDirectory($tenantStoragePath))->toBeFalse();
|
|
||||||
expect(File::isDirectory($centralStoragePath))->toBeTrue();
|
expect(File::isDirectory($centralStoragePath))->toBeTrue();
|
||||||
})->with([true, false]);
|
expect(File::isDirectory($tenantStoragePath($tenant)))->toBeFalse();
|
||||||
|
})->with([
|
||||||
|
'filesystem bootstrapper enabled' => true,
|
||||||
|
'filesystem bootstrapper disabled' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
test('DeleteTenantStorage does not delete the central storage directory when the filesystem bootstrapper is disabled', function () {
|
test('DeleteTenantStorage never deletes the central storage directory', function () {
|
||||||
config(['tenancy.bootstrappers' => []]);
|
|
||||||
|
|
||||||
$centralStoragePath = storage_path();
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
|
|
||||||
|
$centralStoragePath = FilesystemTenancyBootstrapper::getBoundCentralStoragePath();
|
||||||
|
$tenantStoragePath = FilesystemTenancyBootstrapper::getTenantStoragePath($tenant);
|
||||||
|
|
||||||
|
File::ensureDirectoryExists($centralStoragePath . '/app');
|
||||||
|
|
||||||
|
// Make the tenant storage path a symlink to the central storage directory
|
||||||
|
File::deleteDirectory($tenantStoragePath);
|
||||||
|
symlink($centralStoragePath, $tenantStoragePath);
|
||||||
|
|
||||||
|
expect(realpath($tenantStoragePath))->toBe(realpath($centralStoragePath));
|
||||||
|
|
||||||
(new DeleteTenantStorage($tenant))->handle();
|
(new DeleteTenantStorage($tenant))->handle();
|
||||||
|
|
||||||
expect(File::isDirectory($centralStoragePath))->toBeTrue();
|
expect(File::isDirectory($centralStoragePath))->toBeTrue();
|
||||||
|
expect(File::isDirectory($centralStoragePath . '/app'))->toBeTrue();
|
||||||
|
expect(is_link($tenantStoragePath))->toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the framework/cache directory is created when storage_path is scoped', function (bool $suffixStoragePath) {
|
test('the framework/cache directory is created when storage_path is scoped', function (bool $suffixStoragePath) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue