UNPKG

cloudrx

Version:

TypeScript library for streaming cloud provider events using RxJS with automatic persistence and replay capabilities

75 lines 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamoDBLocalContainer = void 0; const testcontainers_1 = require("testcontainers"); const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); class DynamoDBLocalContainer { constructor(logger) { this.startedContainer = null; this.client = null; this.logger = logger; this.container = new testcontainers_1.GenericContainer('amazon/dynamodb-local:latest') .withExposedPorts(8000) .withCommand(['-jar', 'DynamoDBLocal.jar', '-inMemory', '-sharedDb']); } async start() { try { this.logger.info?.('Starting DynamoDB Local container...'); this.startedContainer = await this.container.start(); const port = this.startedContainer.getMappedPort(8000); const endpoint = `http://localhost:${port}`; this.logger.info?.(`DynamoDB Local started at ${endpoint}`); this.client = new client_dynamodb_1.DynamoDBClient({ endpoint, region: 'local', credentials: { accessKeyId: 'fake', secretAccessKey: 'fake', }, }); } catch (error) { if (error instanceof Error) { if (error.message.includes('Cannot connect to the Docker daemon')) { throw new Error('❌ Docker is not running!\n\n' + 'Please start Docker Desktop or Docker daemon before running integration tests.\n' + 'Integration tests require DynamoDB Local which runs in a Docker container.\n\n' + 'To run tests without Docker, use: npm run test (unit tests only)'); } if (error.message.includes('docker: command not found')) { throw new Error('❌ Docker is not installed!\n\n' + 'Please install Docker Desktop to run integration tests.\n' + 'Integration tests require DynamoDB Local which runs in a Docker container.\n\n' + 'To run tests without Docker, use: npm run test (unit tests only)'); } } throw new Error(`Failed to start DynamoDB Local container: ${error}`); } } async stop() { if (this.startedContainer) { this.logger.info?.('Stopping DynamoDB Local container...'); await this.startedContainer.stop(); this.startedContainer = null; } if (this.client) { this.client.destroy(); this.client = null; } } getClient() { if (!this.client) { throw new Error('DynamoDB Local container not started'); } return this.client; } getEndpoint() { if (!this.startedContainer) { throw new Error('DynamoDB Local container not started'); } const port = this.startedContainer.getMappedPort(8000); return `http://localhost:${port}`; } } exports.DynamoDBLocalContainer = DynamoDBLocalContainer; //# sourceMappingURL=local.js.map