skipcheck

TM1 Testcontainers · Docs · Containers

Tm1ServerContainer

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

Used in the walkthrough Test your code against a real TM1.

A TM1 server in Docker, for tests, built on the tm1-server image.

The image contains no IBM software, so every container needs a Tm1Source. Most tests don't create containers themselves: they use RequiresTm1, which finds a source from the environment, starts one shared container, and skips the tests when there's no source or no Docker.

By default the server starts with an empty database and the login admin with no password. Once started, the container reads the server's version, available from getTm1Version. If withExpectedVersion was set and the version differs, it fails to start, before any test runs against the wrong TM1.

A client for the server, from its URL and login:

// The container's REST URL and login, in TM1's own security
return Tm1Client.builder().baseUrl(server.getRestUrl()).basicAuth(server.getUsername(), server.getPassword()).build();

A container of a test's own, with IBM's SData sample on one TM1 version:

const source = Tm1Source.discover();
if (!source) throw new Error("Set TM1_HOME_DIR or TM1_BUNDLE_DIR");
// SData's login is admin / apple, and the server must be this version
await using server = new Tm1ServerContainer(source).withSeed(Tm1Seed.SDATA).withExpectedVersion(Tm1Version.parse("11.8.03500.6"));
await server.start();
// Declared after the server, so it's closed before the container stops
await using tm1 = Tm1Client.builder().baseUrl(server.getRestUrl()).basicAuth(server.getUsername(), server.getPassword()).build();
// SData's cubes, such as SalesCube
const cubes = await tm1.cubes.modelCubes(ODataQuery.none().select(Cube.Fields.Name)).toArray();
return cubes.map((cube) => cube.Name!);

Your own database, from a folder in the project:

// A fixture model (.cub, .dim, .pro files and so on), copied in before TM1 starts
await using server = new Tm1ServerContainer(source).withData("test/fixtures/tm1/sales").withCredentials("admin", "apple"); // a login the database has
await server.start();
return server.getRestUrl(); // http://localhost:54321/api/v1/

In Cognos (CAM) security, with withCamSecurity, each Cognos test user logs in as themselves:

await using cognos = new CognosContainer(cognosSource).withUser("admin", "adminpw", "Admins").withUser("viewer", "viewerpw", "Readers");
await using server = new Tm1ServerContainer(tm1Source).withCamSecurity(cognos, "admin");
await server.start(); // starts Cognos first
// Each test user logs in with their own identity, through the LDAP namespace
await using viewer = Tm1Client.builder()
  .baseUrl(server.getRestUrl())
  .authenticator(Tm1Authenticator.camNamespace("viewer", "viewerpw", CognosContainer.NAMESPACE))
  .build();
// TM1 knows the user by their CAMID
const user = await viewer.users.activeUser(ODataQuery.none().select(User.Fields.Name));
return user.Name;

Members

DEFAULT_IMAGE propertyThe tm1-server image, without a tag.
SERVER_IMAGE propertyOverrides the tm1-server image (not used with Tm1Source.PrivateImage), e.g.
REST_PORT propertyThe REST API's port inside the container.
CACHE_VOLUME propertyThe volume bundle installs are cached in, shared by every container on this Docker host (and with the Java, Python and .NET tests).
Tm1ServerContainer constructorA container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.
Tm1ServerContainer constructorA container on image, which must be tm1-server or built on it.
Tm1ServerContainer constructor
shared staticThe container most tests share.
withSeedSeeds an empty database with objects.
withDataCopies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts.
withCredentialsThe login tests should use.
withCamSecurityRuns TM1 in Cognos (CAM) security against cognos.
withCamSecurityRuns TM1 in Cognos (CAM) security through namespace.
withCamSecurity
withAdminServerRegisters this server with a separate Admin Server, as in a deployment with several TM1 servers, instead of running one inside this container (TM1_ADMIN_HOST).
getAdminServerThe Admin Server set with withAdminServer; undefined if this container runs its own.
getCognosThe Cognos set with withCamSecurity; undefined if TM1 uses its own (native) security.
getCamNamespaceThe Cognos namespace TM1's users log on through; undefined in native security.
getCamAdminsThe Cognos test users made TM1 administrators by withCamSecurity.
getAuthorizationThe Authorization header for the container's login.
withExpectedVersionFails startup unless the server reports exactly this version.
getSourceWhere TM1 comes from.
getRestUrlThe REST API's service root as seen from the host, e.g.
getUsernameThe TM1 user name tests should log in as; admin unless set.
getPasswordThe password for getUsername; empty unless set.
getTm1VersionThe version the running server reports.
configure@internal
stopStops and removes the container, and forgets the version it read.
shareNetwork staticPuts two containers that talk to each other on one Docker network.
mountSource staticMounts a TM1 source into a tm1-server container.
defaultImage staticThe image for source.
imageFor static@internal
imageTag staticReleased libraries use the image of the same version; development builds (Java's -SNAPSHOT, npm's -dev and a published -dev.1) use edge, built from master.
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.
withNetworkJoins network (created when the first container on it starts).
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.
withCopyFileToContainerCopies a host file or folder into the container before it starts.
withStartupTimeoutHow long to wait for it to be ready, in milliseconds.
start
[Symbol.asyncDispose]Stops it, for await using.
getLogsIts log, so far.

DEFAULT_IMAGE

property
static DEFAULT_IMAGE

The tm1-server image, without a tag.

SERVER_IMAGE

property
static SERVER_IMAGE

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

REST_PORT

property
static REST_PORT

The REST API's port inside the container.

CACHE_VOLUME

property
static CACHE_VOLUME

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

Tm1ServerContainer

constructor
constructor(source: Tm1Source)

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

Tm1ServerContainer

constructor
constructor(image: string, source: Tm1Source)

A container on image, which must be tm1-server or built on it.

Tm1ServerContainer

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

shared

static
static shared(): Promise<Tm1ServerContainer>

The container most tests share: one per test run (per vitest worker), started on first use with the source Tm1Source.discover finds. Testcontainers removes it when the run ends.

It's marked reusable. If you've turned on Testcontainers reuse (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true), it keeps running between test runs, so tests start instantly, and objects tests leave behind stay too.

Throws

IllegalStateException if no source is configured

withSeed

withSeed(seed: Tm1Seed): this

Seeds an empty database with objects. The default is Tm1Seed.EMPTY, which seeds nothing. Also sets credentials to the seed's login.

withData

withData(dataDir: string): this

Copies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts. Any seed is ignored, since the database isn't empty. Set withCredentials to a login the database has.

Throws

IllegalArgumentException if dataDir isn't a folder

withCredentials

withCredentials(username: string, password: string): this

The login tests should use. The default is admin with no password ("").

withCamSecurity

withCamSecurity(cognos: CognosContainer, ...admins: string[]): this

Runs TM1 in Cognos (CAM) security against cognos: TM1 takes its users from Cognos's test users, who log on with CognosContainer.camAuthorization.

- admins become TM1 administrators, and getUsername is the first of them, so the container's own checks log on as that user; - every group of the test users is added to TM1 (named by its CAMID), so users get their groups at logon.

The two containers share a Docker network: cognos's, or a new one if it has none. Starting TM1 starts Cognos first. Call this before either is started. With a namespace (CognosContainer.Namespace.OIDC needs CognosContainer.withKeycloak), TM1's administrators, groups and this container's own login go through it; LDAP otherwise.

Throws

IllegalArgumentException if no admin is given

withCamSecurity

withCamSecurity(cognos: CognosContainer, namespace: CognosContainer.Namespace, ...admins: string[]): this

Runs TM1 in Cognos (CAM) security through namespace: TM1's administrators, groups and this container's own login go through it. CognosContainer.Namespace.OIDC needs CognosContainer.withKeycloak. @throws IllegalArgumentException if no admin is given

withCamSecurity

withCamSecurity(cognos: CognosContainer, ...rest: (string | CognosContainer.Namespace)[]): this

withAdminServer

withAdminServer(admin: Tm1AdminServerContainer): this

Registers this server with a separate Admin Server, as in a deployment with several TM1 servers, instead of running one inside this container (TM1_ADMIN_HOST). TM1 Web and PAW pointed at that Admin Server list every server registered with it. The two share a Docker network, and starting this server starts the Admin Server first.

getAdminServer

getAdminServer(): Tm1AdminServerContainer | undefined

The Admin Server set with withAdminServer; undefined if this container runs its own.

getCognos

getCognos(): CognosContainer | undefined

The Cognos set with withCamSecurity; undefined if TM1 uses its own (native) security.

getCamNamespace

getCamNamespace(): CognosContainer.Namespace | undefined

The Cognos namespace TM1's users log on through; undefined in native security.

getCamAdmins

getCamAdmins(): readonly string[]

The Cognos test users made TM1 administrators by withCamSecurity.

getAuthorization

getAuthorization(): string

The Authorization header for the container's login: Basic with getUsername and getPassword, or, in CAM security, CAMNamespace for that Cognos user.

withExpectedVersion

withExpectedVersion(version: Tm1Version | string): this

Fails startup unless the server reports exactly this version.

getSource

getSource(): Tm1Source

Where TM1 comes from.

getRestUrl

getRestUrl(): string

The REST API's service root as seen from the host, e.g. http://localhost:54321/api/v1/.

getUsername

getUsername(): string

The TM1 user name tests should log in as; admin unless set.

getPassword

getPassword(): string

The password for getUsername; empty unless set.

getTm1Version

getTm1Version(): Tm1Version

The version the running server reports.

Throws

IllegalStateException if the container isn't started yet

configure

configure(): void

@internal

stop

stop(): Promise<void>

Stops and removes the container, and forgets the version it read.

shareNetwork

static
static shareNetwork(a: GenericContainer, b: GenericContainer): void

Puts two containers that talk to each other on one Docker network: the one either already has, or a new one. Fails if they're on different networks, since neither could then reach the other by name.

mountSource

static
static mountSource( source: Tm1Source, bind: (source: string, target: string, readOnly: boolean) => void, withEnv: (name: string, value: string) => void, ): void

Mounts a TM1 source into a tm1-server container: the install, the bundle folder and cache, or the download settings. Shared with Tm1AdminServerContainer, which runs the same image.

defaultImage

static
static defaultImage(source: Tm1Source): string

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

imageFor

static
static imageFor(setting: string, image: string): string

@internal

imageTag

static
static imageTag(libraryVersion: string): string

Released libraries use the image of the same version; development builds (Java's -SNAPSHOT, npm's -dev and a published -dev.1) use edge, built from master: a development pre-release is published by hand, without the images a tagged release gets.

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.

withNetwork

withNetwork(network: Network | undefined): this

Joins network (created when the first container on it starts).

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.

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.

start

start(): Promise<void>

[Symbol.asyncDispose]

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

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

getLogs

getLogs(): Promise<string>

Its log, so far.