diff --git a/dbal/ts/src/blob/index.ts b/dbal/ts/src/blob/index.ts index e6865bdd6..dc6da4b49 100644 --- a/dbal/ts/src/blob/index.ts +++ b/dbal/ts/src/blob/index.ts @@ -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': diff --git a/dbal/ts/tests/blob/index.test.ts b/dbal/ts/tests/blob/index.test.ts new file mode 100644 index 000000000..951eedc79 --- /dev/null +++ b/dbal/ts/tests/blob/index.test.ts @@ -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' + ) + }) +})