code: index,dbal (2 files)

This commit is contained in:
2025-12-25 19:56:31 +00:00
parent f3bb7b7b0c
commit d5e32ed0f0
2 changed files with 38 additions and 1 deletions

View File

@@ -12,7 +12,6 @@ import { FilesystemStorage } from './filesystem-storage'
/**
* Factory function to create blob storage instances
*/
// TODO: add tests for createBlobStorage (memory, s3, filesystem, unknown type).
export function createBlobStorage(config: BlobStorageConfig): BlobStorage {
switch (config.type) {
case 'memory':

View File

@@ -0,0 +1,38 @@
import { describe, expect, it, vi } from 'vitest'
import { createBlobStorage } from '../../src/blob'
import { FilesystemStorage } from '../../src/blob/filesystem-storage'
import { MemoryStorage } from '../../src/blob/memory-storage'
import { S3Storage } from '../../src/blob/s3-storage'
vi.mock('@aws-sdk/client-s3', () => ({
S3Client: class {},
}), { virtual: true })
describe('createBlobStorage', () => {
it.each([
{
config: { type: 'memory' as const },
expected: MemoryStorage,
description: 'memory storage',
},
{
config: { type: 'filesystem' as const, filesystem: { basePath: '/tmp/dbal-blob-test' } },
expected: FilesystemStorage,
description: 'filesystem storage',
},
{
config: { type: 's3' as const, s3: { bucket: 'test-bucket', region: 'us-east-1' } },
expected: S3Storage,
description: 's3 storage',
},
])('creates $description', ({ config, expected }) => {
const storage = createBlobStorage(config)
expect(storage).toBeInstanceOf(expected)
})
it('throws for unknown type', () => {
expect(() => createBlobStorage({ type: 'unknown' as 'memory' })).toThrow(
'Unknown blob storage type: unknown'
)
})
})