skipcheck

TM1 Testcontainers · Docs · Containers

Tm1EngineContainer

import { Tm1EngineContainer } from "@skipcheck/tm1-testcontainers";

A TM1 v12 engine (Planning Analytics 3.x) in Docker, for tests: the tm1-engine image with TM1 from a Tm1EngineSource, and the MongoDB it keeps its metadata in, on a network of their own. For TM1 11, use Tm1ServerContainer.

One engine holds instances, each holding databases. Most tests use the one instance, tm1, and a database of their own: RequiresTm1Engine gives each test class one. A container you make yourself has the databases you name with withDatabase, or one called tm1:

await using engine = new Tm1EngineContainer(source).withDatabase("planning").withUser("analyst", "Analysts");
await engine.start();
const planning = engine.database("planning");
// http://localhost:54321/tm1/api/v1/Databases('planning')/
const url = planning.getRestUrl();
const analyst = planning.login("analyst");
// ...

TM1 v12 has no passwords of its own. A test logs in through the instance's application (Tm1Login), which this container creates and keeps the credentials of.

Starting takes about 40 seconds, and a database about 10 more to create (createDatabase). The image exists for x86-64 only, as TM1 does; on Apple Silicon it runs under Rosetta.

Members

DEFAULT_IMAGE propertyThe tm1-engine image, without a tag.
ENGINE_IMAGE propertyOverrides the tm1-engine image (not used with Tm1EngineSource.PrivateImage), e.g.
DATASTORE_IMAGE propertyThe MongoDB image the engine's datastore runs.
PORT propertyThe port of TM1's gateway inside the container.
DEFAULT_INSTANCE propertyThe instance databases are in unless one is named.
DEFAULT_DATABASE propertyThe database a container has when none is named.
DATASTORE_ALIAS propertyThe datastore's name on the engine's network.
CACHE_VOLUME propertyThe volume package installs are cached in, shared by every engine container on this Docker host (and with the Java, Python and .NET tests).
OAUTH2_REALM propertyThe Keycloak realm an engine with withOAuth2 takes tokens from.
OAUTH2_CLIENT propertyThe client of that realm a test asks for tokens as, and the audience its tokens carry.
PASS_THROUGH_ALIAS propertyThe name a TM1 server has on the engine's network when logins are passed to it (withPassThrough).
Tm1EngineContainer constructorA container on the default tm1-engine image (or TM1_ENGINE_IMAGE), getting TM1 from source.
Tm1EngineContainer constructorA container from an image of your own, such as a locally built one.
Tm1EngineContainer constructor
shared staticThe engine tests share, started on first use with the source Tm1EngineSource.discover finds; Testcontainers removes it when the run ends.
withNetworkPuts the engine, and its datastore with it, on a network.
withDatabaseAdds a database, in the instance tm1.
withDatabaseAdds a database in a named instance, which is created with an application of its own.
withDatabase
withUserAdds a user to every database, in exactly these groups (created if missing).
withOAuth2Takes OAuth 2.0 logins.
withPassThroughPasses logins on to a TM1 11 server ("pass-through").
withPassThroughAs withPassThrough, to a server that has a name on the network already.
withPassThrough
getPassThroughThe TM1 server logins are passed to, or undefined without withPassThrough.
withLoginGives a user a password to log in with through OAuth 2.0 (withOAuth2).
getKeycloakThe Keycloak the engine takes OAuth 2.0 tokens from, or undefined without withOAuth2.
getSourceWhere TM1 comes from.
getDatastoreThe MongoDB the engine keeps its metadata in, started and stopped with it.
getUrlThe gateway as seen from the host, ending in /, e.g.
getManagementUrlThe management API, which lists and creates instances, applications and databases, e.g.
getRootClientIdThe client ID of the engine's root credentials, for the management API.
getRootClientSecretThe client secret of the engine's root credentials.
getTm1VersionThe version of TM1 the engine runs.
databasesThe databases the engine has now, in every instance.
databaseA database of the instance tm1.Of a running engine, it's one of those the engine had when it started, or when databases, createDatabase or dropDatabase last ran (Java asks the engine each time, which here would need a Promise); before the start, one of those added.
databaseA database of a named instance.
database
createDatabaseCreates a database in the instance tm1 of the running engine, with the users of withUser.
createDatabaseCreates a database in a named instance of the running engine, which must exist.
createDatabase
dropDatabaseDeletes a database of the running engine, with everything in it.
loginA login to an instance, through its first application the image holds the secret of.
passThroughLoginA pass-through login.
passThroughLoginWithA pass-through login with a header of the caller's own, such as a CAM passport.
passesToCamWhether logins are passed to a server in CAM security, whose users are Cognos's.
oauth2LoginA login through OAuth 2.0, as a user given a password with withLogin.
realmThe realm the Keycloak imports, as JSON.
configuredWhat's passed to the image as TM1_DATABASES.
startStarts the datastore, then the engine, on one network, and waits until TM1 is set up.
configure@internal
stopStops and removes the engine and its datastore, and forgets what it read from them.
awaitSetup staticWaits until the image has created every instance, application, database and user, and every database is ready.
defaultImage staticThe image for source.
getDockerImageNameThe image it runs.
getEnvMapIts environment variables, so far.
getCommandPartsThe command it runs, if not the image's.
getExposedPortsThe ports it exposes on the Docker host.
getNetworkThe network it joins, or undefined for Docker's default bridge.
getNetworkAliasesIts names on getNetwork.
getDependenciesWhat starts before it.
getLabelsThe labels set with withLabel.
isShouldBeReusedWhether it asks to be kept for later runs (withReuse).
getCopiedFilesThe files and folders copied in with withCopyFileToContainer.
getBindsThe bind mounts, source:target[:ro], the source a host folder or a volume.
getContainerThe started container.
isRunning
getHostThe host its ports are mapped on.
getContainerIdThe Docker container's ID.
getMappedPortThe host port port is mapped to.
withEnvSets an environment variable, or several.
withEnvSets several environment variables at once.
withEnv
withCommandRuns commandParts in place of the image's command.
withExposedPortsExposes ports on the Docker host, each on a free port.
withNetworkAliasesAdds names it's reached by on getNetwork.
dependsOnStarts startables before it.
withExtraHostAdds an /etc/hosts entry.
withHostnameSets the container's host name.
withReuseKeeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run.
withLabelAdds a Docker label.
getCopiedContentsThe text to be written into the container, by the path it's written to.
withCopyFileToContainerCopies a host file or folder into the container before it starts.
withStartupTimeoutHow long to wait for it to be ready, in milliseconds.
[Symbol.asyncDispose]Stops it, for await using.
getLogsIts log, so far.

DEFAULT_IMAGE

property
static DEFAULT_IMAGE

The tm1-engine image, without a tag.

ENGINE_IMAGE

property
static ENGINE_IMAGE

Overrides the tm1-engine image (not used with Tm1EngineSource.PrivateImage), e.g. tm1-engine:local for a local build.

DATASTORE_IMAGE

property
static DATASTORE_IMAGE

The MongoDB image the engine's datastore runs.

PORT

property
static PORT

The port of TM1's gateway inside the container: the REST API, logins and management.

DEFAULT_INSTANCE

property
static DEFAULT_INSTANCE

The instance databases are in unless one is named.

DEFAULT_DATABASE

property
static DEFAULT_DATABASE

The database a container has when none is named.

DATASTORE_ALIAS

property
static DATASTORE_ALIAS

The datastore's name on the engine's network.

CACHE_VOLUME

property
static CACHE_VOLUME

The volume package installs are cached in, shared by every engine container on this Docker host (and with the Java, Python and .NET tests). Only the first container to see a package installs it. Remove the volume to clear it.

OAUTH2_REALM

property
static OAUTH2_REALM

The Keycloak realm an engine with withOAuth2 takes tokens from.

OAUTH2_CLIENT

property
static OAUTH2_CLIENT

The client of that realm a test asks for tokens as, and the audience its tokens carry.

PASS_THROUGH_ALIAS

property
static PASS_THROUGH_ALIAS

The name a TM1 server has on the engine's network when logins are passed to it (withPassThrough).

Tm1EngineContainer

constructor
constructor(source: Tm1EngineSource)

A container on the default tm1-engine image (or TM1_ENGINE_IMAGE), getting TM1 from source.

Tm1EngineContainer

constructor
constructor(image: string, source: Tm1EngineSource)

A container from an image of your own, such as a locally built one.

Tm1EngineContainer

constructor
constructor(imageOrSource: string | Tm1EngineSource, maybeSource?: Tm1EngineSource)

shared

static
static shared(): Promise<Tm1EngineContainer>

The engine tests share, started on first use with the source Tm1EngineSource.discover finds; Testcontainers removes it when the run ends. It has one database, tm1; requiresTm1Engine creates one more for each test file.

It's one per module registry, where Java's is one per JVM. vitest isolates test files by default, each with its own modules, so that is **one engine per test file**, started (about 40 seconds) by the first test of the file that needs it. It's one for the whole run only when the files share their modules: isolate: false, or a single worker without isolation.

It isn't marked reusable: an engine and its datastore belong together, and a kept engine would keep every database tests left in it.

Throws

IllegalStateException if no source is configured

withNetwork

withNetwork(network: Network | undefined): this

Puts the engine, and its datastore with it, on a network. They have one of their own unless this is called.

withDatabase

withDatabase(name: string): this

Adds a database, in the instance tm1. Without any, the container has one called tm1.

Parameters

name
the database's name: at least three letters, digits, _ or -. Sales and sales are two databases

withDatabase

withDatabase(instance: string, name: string): this

Adds a database in a named instance, which is created with an application of its own. An instance's users, sessions and applications are separate from another's.

withDatabase

withDatabase(instance: string, name?: string): this

withUser

withUser(name: string, ...groups: string[]): this

Adds a user to every database, in exactly these groups (created if missing). A new database has one user already: admin, in the ADMIN group.

Throws

IllegalArgumentException if a name isn't one the image takes, or the user is there

withOAuth2

withOAuth2(keycloak: KeycloakContainer): this

Takes OAuth 2.0 logins: tokens from a Keycloak, which gets a realm (tm1) with the users given a password by withLogin. A test then logs in with Tm1Database.oauth2Login. Logins through the engine's application (Tm1Database.login) keep working beside it.

The Keycloak joins the engine's network, unless it has one already, which the engine then joins. It's yours to stop: the engine only starts it first. Give it one that isn't started, and that no other engine uses: the same one again changes nothing, and another is refused.

// Starting the engine starts Keycloak first; the Keycloak is yours to stop
await using keycloak = new KeycloakContainer();
await using engine = new Tm1EngineContainer(source).withUser("analyst", "Analysts").withLogin("analyst", "analystpw").withOAuth2(keycloak);
await engine.start();
const db = engine.database("tm1");
// A token from Keycloak, with the analyst's password, sent to TM1 as Bearer
const request = await db.oauth2Login("analyst").authorizeWithToken();
const response = await fetch(db.getRestUrl() + "Cubes?$select=Name", request);

Parameters

keycloak
the Keycloak to take tokens from

Throws

IllegalStateException for a Keycloak that's running, or another engine's, or a second one for this engine, or with withPassThrough

withPassThrough

withPassThrough(server: Tm1ServerContainer): this

Passes logins on to a TM1 11 server ("pass-through"): TM1 v12 asks it who a login is, so that server's users log in here with what they have there. A test logs in with Tm1Database.passThroughLogin. Logins through the engine's application (Tm1Database.login) keep working beside it.

- A user has to be in the database too: add each with withUser. admin always is. - **A server in Cognos (CAM) security** (Tm1ServerContainer.withCamSecurity) answers a login with the user's CAMID. The engine's users are then Cognos's test users, each made under its CAMID, and the server's administrators are administrators here too. TM1 v12 learns no groups from Cognos: a user has the groups withUser gives. - Not together with withOAuth2: with both, TM1 takes tokens and refuses the rest.

The server joins the engine's network, unless it has one already, which the engine and its datastore then join. Starting the engine starts the server first. Give it one that isn't started: it gets the name the engine reaches it by, PASS_THROUGH_ALIAS, so one network holds one such server.

// Starting the engine starts the TM1 11 server first; the server is yours to stop
await using server = new Tm1ServerContainer(tm1).withSeed(Tm1Seed.SDATA);
await using engine = new Tm1EngineContainer(source).withPassThrough(server);
await engine.start();
const db = engine.database("tm1");
// The sample database's admin / apple, which TM1 v12 asks the server about
const request = await db.passThroughLogin().authorize();
const response = await fetch(db.getRestUrl() + "Cubes?$select=Name", request);

Parameters

server
the TM1 server that checks logins

Throws

IllegalStateException for a server that's running, a second server for this engine, or with withOAuth2

withPassThrough

withPassThrough(server: Tm1ServerContainer, alias: string | undefined): this

As withPassThrough, to a server that has a name on the network already: an environment's.

withPassThrough

withPassThrough(server: Tm1ServerContainer, alias?: string): this

getPassThrough

getPassThrough(): Tm1ServerContainer | undefined

The TM1 server logins are passed to, or undefined without withPassThrough.

withLogin

withLogin(user: string, password: string): this

Gives a user a password to log in with through OAuth 2.0 (withOAuth2). TM1 v12 keeps no passwords itself: it's the Keycloak's. The user is one added with withUser, or admin.

Throws

IllegalArgumentException if the name isn't one the image takes, or the password is empty

getKeycloak

getKeycloak(): KeycloakContainer | undefined

The Keycloak the engine takes OAuth 2.0 tokens from, or undefined without withOAuth2.

getSource

getSource(): Tm1EngineSource

Where TM1 comes from.

getDatastore

getDatastore(): GenericContainer

The MongoDB the engine keeps its metadata in, started and stopped with it.

getUrl

getUrl(): string

The gateway as seen from the host, ending in /, e.g. http://localhost:54321/.

getManagementUrl

getManagementUrl(): string

The management API, which lists and creates instances, applications and databases, e.g. http://localhost:54321/manage/v1/. It takes the root credentials as Basic authentication (getRootClientId, getRootClientSecret).

getRootClientId

getRootClientId(): string

The client ID of the engine's root credentials, for the management API.

Throws

IllegalStateException if the container isn't started yet

getRootClientSecret

getRootClientSecret(): string

The client secret of the engine's root credentials.

Throws

IllegalStateException if the container isn't started yet

getTm1Version

getTm1Version(): Tm1Version

The version of TM1 the engine runs. Only available once started.

Throws

IllegalStateException if the container isn't started yet

databases

databases(): Promise<Tm1Database[]>

The databases the engine has now, in every instance: asked of the engine each time.

database

database(name: string): Tm1Database

A database of the instance tm1.

Of a running engine, it's one of those the engine had when it started, or when databases, createDatabase or dropDatabase last ran (Java asks the engine each time, which here would need a Promise); before the start, one of those added.

Throws

IllegalArgumentException if there's no such database

database

database(instance: string, name: string): Tm1Database

A database of a named instance.

Throws

IllegalArgumentException if there's no such database

database

database(instance: string, name?: string): Tm1Database

createDatabase

createDatabase(name: string): Promise<Tm1Database>

Creates a database in the instance tm1 of the running engine, with the users of withUser. Takes about 10 seconds.

createDatabase

createDatabase(instance: string, name: string): Promise<Tm1Database>

Creates a database in a named instance of the running engine, which must exist.

createDatabase

createDatabase(instance: string, name?: string): Promise<Tm1Database>

dropDatabase

dropDatabase(database: Tm1Database): Promise<void>

Deletes a database of the running engine, with everything in it. Takes about 7 seconds.

login

login(instance: string, user: string): Tm1Login

A login to an instance, through its first application the image holds the secret of: TM1 shows a secret once, so an application made elsewhere is listed without.

passThroughLogin

passThroughLogin(database: Tm1Database, user: string | undefined, password: string | undefined): Tm1Login

A pass-through login: the header the TM1 server takes, for a user it knows.

Parameters

user
the user's name there, or undefined for the server's own login
password
the password, or undefined for the one the containers know

passThroughLoginWith

passThroughLoginWith(database: Tm1Database, authorization: string): Tm1Login

A pass-through login with a header of the caller's own, such as a CAM passport.

passesToCam

passesToCam(): boolean

Whether logins are passed to a server in CAM security, whose users are Cognos's.

oauth2Login

oauth2Login(database: Tm1Database, user: string): Tm1Login

A login through OAuth 2.0, as a user given a password with withLogin.

realm

realm(): string

The realm the Keycloak imports, as JSON: a client whose tokens carry the audience TM1 expects, and the users who have a password.

Throws

IllegalStateException if someone with a password isn't a user of the engine

configured

configured(): string[]

What's passed to the image as TM1_DATABASES: what was added, or the default.

start

start(): Promise<void>

Starts the datastore, then the engine, on one network, and waits until TM1 is set up.

configure

configure(): void

@internal

stop

stop(): Promise<void>

Stops and removes the engine and its datastore, and forgets what it read from them.

awaitSetup

static
static awaitSetup(probe: SetupProbe, timeout: number, interval = 1_000): Promise<void>

Waits until the image has created every instance, application, database and user, and every database is ready: what its health check reports. Fails at once if the container has exited.

defaultImage

static
static defaultImage(source: Tm1EngineSource): string

The image for source: a private image as it is; otherwise TM1_ENGINE_IMAGE if set; otherwise DEFAULT_IMAGE tagged as tm1-server's is, with this library's version (edge for a development build).

getDockerImageName

getDockerImageName(): string

The image it runs.

getEnvMap

getEnvMap(): ReadonlyMap<string, string>

Its environment variables, so far.

getCommandParts

getCommandParts(): readonly string[]

The command it runs, if not the image's.

getExposedPorts

getExposedPorts(): readonly number[]

The ports it exposes on the Docker host.

getNetwork

getNetwork(): Network | undefined

The network it joins, or undefined for Docker's default bridge.

getNetworkAliases

getNetworkAliases(): readonly string[]

Its names on getNetwork.

getDependencies

getDependencies(): readonly Startable[]

What starts before it.

getLabels

getLabels(): ReadonlyMap<string, string>

The labels set with withLabel.

isShouldBeReused

isShouldBeReused(): boolean

Whether it asks to be kept for later runs (withReuse).

getCopiedFiles

getCopiedFiles(): ReadonlyMap<string, string>

The files and folders copied in with withCopyFileToContainer: the path in the container to the path on the host.

getBinds

getBinds(): string[]

The bind mounts, source:target[:ro], the source a host folder or a volume.

getContainer

getContainer(): StartedTestContainer

The started container.

Throws

IllegalStateException if it isn't started

isRunning

isRunning(): boolean

getHost

getHost(): string

The host its ports are mapped on.

getContainerId

getContainerId(): string

The Docker container's ID.

getMappedPort

getMappedPort(port: number): number

The host port port is mapped to.

withEnv

withEnv(name: string, value: string): this

Sets an environment variable, or several.

withEnv

withEnv(variables: Readonly<Record<string, string>> | ReadonlyMap<string, string>): this

Sets several environment variables at once.

withEnv

withEnv(name: string | Readonly<Record<string, string>> | ReadonlyMap<string, string>, value?: string): this

withCommand

withCommand(...commandParts: string[]): this

Runs commandParts in place of the image's command.

withExposedPorts

withExposedPorts(...ports: number[]): this

Exposes ports on the Docker host, each on a free port.

withNetworkAliases

withNetworkAliases(...aliases: string[]): this

Adds names it's reached by on getNetwork.

dependsOn

dependsOn(...startables: Startable[]): this

Starts startables before it.

withExtraHost

withExtraHost(host: string, ipAddress: string): this

Adds an /etc/hosts entry.

withHostname

withHostname(hostname: string): this

Sets the container's host name.

withReuse

withReuse(reusable: boolean): this

Keeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run.

withLabel

withLabel(key: string, value: string): this

Adds a Docker label.

getCopiedContents

getCopiedContents(): ReadonlyMap<string, string>

The text to be written into the container, by the path it's written to.

withCopyFileToContainer

withCopyFileToContainer(hostPath: string, containerPath: string): this

Copies a host file or folder into the container before it starts.

withStartupTimeout

withStartupTimeout(timeout: number): this

How long to wait for it to be ready, in milliseconds.

[Symbol.asyncDispose]

[Symbol.asyncDispose](): Promise<void>

Stops it, for await using: the same as stop.

getLogs

getLogs(): Promise<string>

Its log, so far.