@testcontainers/azure-cosmosdb-emulator
Version:
Azure Cosmos DB Emulator module for Testcontainers
74 lines • 2.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StartedAzureCosmosDbEmulatorContainer = exports.AzureCosmosDbEmulatorContainer = void 0;
const testcontainers_1 = require("testcontainers");
const DEFAULT_KEY = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; // default key for Cosmos DB Emulator
const DEFAULT_PROTOCOL = "http";
const DEFAULT_TELEMETRY_ENABLED = false;
const DEFAULT_EXPLORER_ENABLED = false;
const COSMOS_READY_LOG_MESSAGE = "Now listening on: ";
class AzureCosmosDbEmulatorContainer extends testcontainers_1.GenericContainer {
key = DEFAULT_KEY;
protocol = DEFAULT_PROTOCOL;
telemetryEnabled = DEFAULT_TELEMETRY_ENABLED;
explorerEnabled = DEFAULT_EXPLORER_ENABLED;
portGenerator;
constructor(image) {
super(image);
this.portGenerator = new testcontainers_1.RandomPortGenerator();
this.withWaitStrategy(testcontainers_1.Wait.forLogMessage(COSMOS_READY_LOG_MESSAGE));
}
withProtocol(protocol) {
this.protocol = protocol;
return this;
}
withTelemetryEnabled(telemetryEnabled) {
this.telemetryEnabled = telemetryEnabled;
return this;
}
async start() {
const port = await this.portGenerator.generatePort();
this.withExposedPorts({
host: port,
container: port,
});
this.withEnvironment({
PROTOCOL: this.protocol,
PORT: port.toString(),
ENABLE_TELEMETRY: this.telemetryEnabled.toString(),
ENABLE_EXPLORER: this.explorerEnabled.toString(),
});
return new StartedAzureCosmosDbEmulatorContainer(await super.start(), this.key, port, this.protocol);
}
}
exports.AzureCosmosDbEmulatorContainer = AzureCosmosDbEmulatorContainer;
class StartedAzureCosmosDbEmulatorContainer extends testcontainers_1.AbstractStartedContainer {
key;
port;
protocol;
constructor(startedContainer, key, port, protocol) {
super(startedContainer);
this.key = key;
this.port = port;
this.protocol = protocol;
}
getPort() {
return this.port;
}
getKey() {
return this.key;
}
getEndpoint() {
const proto = this.protocol === "http" ? "http" : "https";
return `${proto}://${this.getHost()}:${this.getPort()}`;
}
/**
* Returns a connection URI in the format:
* AccountEndpoint=[protocol]://[host]:[port];AccountKey=[key];
*/
getConnectionUri() {
return `AccountEndpoint=${this.getEndpoint()};AccountKey=${this.getKey()};`;
}
}
exports.StartedAzureCosmosDbEmulatorContainer = StartedAzureCosmosDbEmulatorContainer;
//# sourceMappingURL=azure-cosmosdb-emulator-container.js.map