Skip to content

Commit

Permalink
Added default handling for Mac M1 ARM64 image for EventStoreDB TestCo…
Browse files Browse the repository at this point in the history
…ntainer.

Changed EventStoreDB test container options to be in the nested object and false by default. That should make them more straightforward.
  • Loading branch information
oskardudycz committed Apr 28, 2024
1 parent 61f33c5 commit cefd379
Showing 1 changed file with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,54 @@ import {
} from 'testcontainers';
import type { Environment } from 'testcontainers/build/types';

const EVENTSTOREDB_PORT = 2113;
const EVENTSTOREDB_TCP_PORT = 1113;
const EVENTSTOREDB_TCP_PORTS = [EVENTSTOREDB_TCP_PORT, EVENTSTOREDB_PORT];
const EVENTSTOREDB_IMAGE_NAME = 'eventstore/eventstore';
const EVENTSTOREDB_IMAGE_TAG = '23.10.1-bookworm-slim';
export const EVENTSTOREDB_PORT = 2113;
export const EVENTSTOREDB_TCP_PORT = 1113;
export const EVENTSTOREDB_TCP_PORTS = [
EVENTSTOREDB_TCP_PORT,
EVENTSTOREDB_PORT,
];
export const EVENTSTOREDB_IMAGE_NAME = 'eventstore/eventstore';
export const EVENTSTOREDB_IMAGE_TAG = '23.10.1-bookworm-slim';
export const EVENTSTOREDB_ARM64_IMAGE_TAG = '23.10.1-alpha-arm64v8';

export const EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== 'arm64' ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;

export type EventStoreDBContainerOptions = {
disableProjections?: boolean;
isSecure?: boolean;
useFileStorage?: boolean;
withoutReuse?: boolean;
};

export const defaultEventStoreDBContainerOptions: EventStoreDBContainerOptions =
{
disableProjections: false,
isSecure: false,
useFileStorage: false,
withoutReuse: false,
};

export class EventStoreDBContainer extends GenericContainer {
private readonly tcpPorts = EVENTSTOREDB_TCP_PORTS;

constructor(
image = `${EVENTSTOREDB_IMAGE_NAME}:${EVENTSTOREDB_IMAGE_TAG}`,
runProjections = true,
isInsecure = true,
emptyDatabase = true,
withoutReuse = false,
image = EVENTSTOREDB_DEFAULT_IMAGE,
options: EventStoreDBContainerOptions = defaultEventStoreDBContainerOptions,
) {
super(image);

const environment: Environment = {
...(runProjections
...(!options.disableProjections
? {
EVENTSTORE_RUN_PROJECTIONS: 'ALL',
}
: {}),
...(isInsecure
...(!options.isSecure
? {
EVENTSTORE_INSECURE: 'true',
}
: {}),
...(!emptyDatabase
...(options.useFileStorage
? {
EVENTSTORE_MEM_DB: 'false',
EVENTSTORE_DB: '/data/integration-tests',
Expand All @@ -51,7 +69,7 @@ export class EventStoreDBContainer extends GenericContainer {

this.withEnvironment(environment).withExposedPorts(...this.tcpPorts);

if (!withoutReuse) this.withReuse();
if (!options.withoutReuse) this.withReuse();
}

async start(): Promise<StartedEventStoreDBContainer> {
Expand Down

0 comments on commit cefd379

Please sign in to comment.