UNPKG

@testcontainers/gcloud

Version:
66 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StartedSpannerEmulatorContainer = exports.SpannerEmulatorContainer = void 0; const grpc_js_1 = require("@grpc/grpc-js"); const testcontainers_1 = require("testcontainers"); const GRPC_PORT = 9010; /** * SpannerEmulatorContainer runs the Cloud Spanner emulator via the GCloud CLI image. */ class SpannerEmulatorContainer extends testcontainers_1.GenericContainer { projectId; constructor(image) { super(image); // only gRPC port is supported this.withExposedPorts(GRPC_PORT).withWaitStrategy(testcontainers_1.Wait.forLogMessage(/.*Cloud Spanner emulator running\..*/, 1)); } /** * Sets the GCP project ID to use with the emulator. */ withProjectId(projectId) { this.projectId = projectId; return this; } async start() { const selectedProject = this.projectId ?? "test-project"; const started = await super.start(); return new StartedSpannerEmulatorContainer(started, selectedProject); } } exports.SpannerEmulatorContainer = SpannerEmulatorContainer; /** * A running Spanner emulator instance with endpoint getters and helper access. */ class StartedSpannerEmulatorContainer extends testcontainers_1.AbstractStartedContainer { projectId; constructor(startedTestContainer, projectId) { super(startedTestContainer); this.projectId = projectId; } /** * @returns mapped port for gRPC. */ getGrpcPort() { return this.getMappedPort(GRPC_PORT); } /** * @returns host:port for gRPC. */ getEmulatorGrpcEndpoint() { return `${this.getHost()}:${this.getGrpcPort()}`; } /** * @returns the GCP project ID used by the emulator. */ getProjectId() { return this.projectId; } /** * @returns insecure credentials for emulator. */ getSslCredentials() { return grpc_js_1.credentials.createInsecure(); } } exports.StartedSpannerEmulatorContainer = StartedSpannerEmulatorContainer; //# sourceMappingURL=spanner-emulator-container.js.map