mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:14:03 +00:00
Use more direct assertions in the tests that assert the actual behavior, keep simpler/less direct assertions in tests that don't require direct assertions, add comments to clarify the behavior
This commit is contained in:
parent
e133c87c66
commit
58a2447adc
1 changed files with 10 additions and 6 deletions
|
|
@ -42,6 +42,7 @@ test('storage path channels get tenant-specific paths by default', function () {
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$centralStoragePath = storage_path();
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
|
|
||||||
// Storage path channels are 'single' and 'daily' by default.
|
// Storage path channels are 'single' and 'daily' by default.
|
||||||
|
|
@ -54,10 +55,10 @@ test('storage path channels get tenant-specific paths by default', function () {
|
||||||
tenancy()->initialize($tenant);
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
// Path should now point to the log in the tenant's storage directory
|
// Path should now point to the log in the tenant's storage directory
|
||||||
$tenantLogPath = "storage/tenant{$tenant->id}/logs/laravel.log";
|
$tenantLogPath = "{$centralStoragePath}/tenant{$tenant->id}/logs/laravel.log";
|
||||||
expect(config("logging.channels.{$channel}.path"))
|
expect(config("logging.channels.{$channel}.path"))
|
||||||
->not()->toBe($originalPath)
|
->not()->toBe($originalPath)
|
||||||
->toEndWith($tenantLogPath);
|
->toBe($tenantLogPath);
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
|
|
@ -119,15 +120,16 @@ test('channel overrides work correctly with both arrays and closures', function
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$centralStoragePath = storage_path();
|
||||||
$originalSinglePath = config('logging.channels.single.path');
|
$originalSinglePath = config('logging.channels.single.path');
|
||||||
|
|
||||||
$tenant = Tenant::create(['id' => 'tenant1', 'webhookUrl' => 'tenant-webhook']);
|
$tenant = Tenant::create(['webhookUrl' => 'tenant-webhook']);
|
||||||
|
|
||||||
// Test both array mapping and closure-based overrides
|
// Test both array mapping and closure-based overrides
|
||||||
LogTenancyBootstrapper::$channelOverrides = [
|
LogTenancyBootstrapper::$channelOverrides = [
|
||||||
'slack' => ['url' => 'webhookUrl'], // slack.url will be mapped to $tenant->webhookUrl
|
'slack' => ['url' => 'webhookUrl'], // slack.url will be mapped to $tenant->webhookUrl
|
||||||
'single' => function (Tenant $tenant, array $channel) {
|
'single' => function (Tenant $tenant, array $channel) use ($centralStoragePath) {
|
||||||
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
return array_merge($channel, ['path' => $centralStoragePath . "/logs/override-{$tenant->id}.log"]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -138,7 +140,7 @@ test('channel overrides work correctly with both arrays and closures', function
|
||||||
expect(config('logging.channels.slack.username'))->toBe('Default'); // Default username, remains default unless overridden
|
expect(config('logging.channels.slack.username'))->toBe('Default'); // Default username, remains default unless overridden
|
||||||
|
|
||||||
// Closure overrides work
|
// Closure overrides work
|
||||||
expect(config('logging.channels.single.path'))->toEndWith('storage/logs/override-tenant1.log');
|
expect(config('logging.channels.single.path'))->toBe("{$centralStoragePath}/logs/override-{$tenant->id}.log");
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
|
|
@ -307,6 +309,8 @@ test('stack logs are written to all configured channels with tenant-specific pat
|
||||||
// Central context stack log
|
// Central context stack log
|
||||||
logger('central');
|
logger('central');
|
||||||
$centralSingleLogPath = storage_path('logs/laravel.log');
|
$centralSingleLogPath = storage_path('logs/laravel.log');
|
||||||
|
|
||||||
|
// The single and daily channels have the same path in the config, but the daily driver parses the file name so that the date is included in the file name
|
||||||
$centralDailyLogPath = storage_path("logs/laravel-{$today}.log");
|
$centralDailyLogPath = storage_path("logs/laravel-{$today}.log");
|
||||||
|
|
||||||
expect(file_get_contents($centralSingleLogPath))->toContain('central');
|
expect(file_get_contents($centralSingleLogPath))->toContain('central');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue