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 property | The tm1-server image, without a tag. |
SERVER_IMAGE property | Overrides the tm1-server image (not used with Tm1Source.PrivateImage), e.g. |
REST_PORT property | The REST API's port inside the container. |
CACHE_VOLUME property | The volume bundle installs are cached in, shared by every container on this Docker host (and with the Java, Python and .NET tests). |
Tm1ServerContainer constructor | A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source. |
Tm1ServerContainer constructor | A container on image, which must be tm1-server or built on it. |
Tm1ServerContainer constructor | |
shared static | The container most tests share. |
withSeed | Seeds an empty database with objects. |
withData | Copies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts. |
withCredentials | The login tests should use. |
withCamSecurity | Runs TM1 in Cognos (CAM) security against cognos. |
withCamSecurity | Runs TM1 in Cognos (CAM) security through namespace. |
withCamSecurity | |
withAdminServer | 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). |
getAdminServer | The Admin Server set with withAdminServer; undefined if this container runs its own. |
getCognos | The Cognos set with withCamSecurity; undefined if TM1 uses its own (native) security. |
getCamNamespace | The Cognos namespace TM1's users log on through; undefined in native security. |
getCamAdmins | The Cognos test users made TM1 administrators by withCamSecurity. |
getAuthorization | The Authorization header for the container's login. |
withExpectedVersion | Fails startup unless the server reports exactly this version. |
getSource | Where TM1 comes from. |
getRestUrl | The REST API's service root as seen from the host, e.g. |
getUsername | The TM1 user name tests should log in as; admin unless set. |
getPassword | The password for getUsername; empty unless set. |
getTm1Version | The version the running server reports. |
configure | @internal |
stop | Stops and removes the container, and forgets the version it read. |
shareNetwork static | Puts two containers that talk to each other on one Docker network. |
mountSource static | Mounts a TM1 source into a tm1-server container. |
defaultImage static | The image for source. |
imageFor static | @internal |
imageTag static | 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. |
getDockerImageName | The image it runs. |
getEnvMap | Its environment variables, so far. |
getCommandParts | The command it runs, if not the image's. |
getExposedPorts | The ports it exposes on the Docker host. |
getNetwork | The network it joins, or undefined for Docker's default bridge. |
getNetworkAliases | Its names on getNetwork. |
getDependencies | What starts before it. |
getLabels | The labels set with withLabel. |
isShouldBeReused | Whether it asks to be kept for later runs (withReuse). |
getCopiedFiles | The files and folders copied in with withCopyFileToContainer. |
getBinds | The bind mounts, source:target[:ro], the source a host folder or a volume. |
getContainer | The started container. |
isRunning | |
getHost | The host its ports are mapped on. |
getContainerId | The Docker container's ID. |
getMappedPort | The host port port is mapped to. |
withEnv | Sets an environment variable, or several. |
withEnv | Sets several environment variables at once. |
withEnv | |
withCommand | Runs commandParts in place of the image's command. |
withExposedPorts | Exposes ports on the Docker host, each on a free port. |
withNetwork | Joins network (created when the first container on it starts). |
withNetworkAliases | Adds names it's reached by on getNetwork. |
dependsOn | Starts startables before it. |
withExtraHost | Adds an /etc/hosts entry. |
withHostname | Sets the container's host name. |
withReuse | 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 | Adds a Docker label. |
withCopyFileToContainer | Copies a host file or folder into the container before it starts. |
withStartupTimeout | How long to wait for it to be ready, in milliseconds. |
start | |
[Symbol.asyncDispose] | Stops it, for await using. |
getLogs | Its log, so far. |
DEFAULT_IMAGE
propertystatic DEFAULT_IMAGEThe tm1-server image, without a tag.
SERVER_IMAGE
propertystatic SERVER_IMAGEOverrides the tm1-server image (not used with Tm1Source.PrivateImage), e.g. tm1-server:local for a local build.
REST_PORT
propertystatic REST_PORTThe REST API's port inside the container.
CACHE_VOLUME
propertystatic CACHE_VOLUMEThe 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
constructorconstructor(source: Tm1Source)A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.
Tm1ServerContainer
constructorconstructor(image: string, source: Tm1Source)A container on image, which must be tm1-server or built on it.
Tm1ServerContainer
constructorconstructor(imageOrSource: string | Tm1Source, maybeSource?: Tm1Source)withSeed
withSeed(seed: Tm1Seed): thisSeeds 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): thisCopies 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
dataDirisn't a folder
withCredentials
withCredentials(username: string, password: string): thisThe login tests should use. The default is admin with no password ("").
withCamSecurity
withCamSecurity(cognos: CognosContainer, ...admins: string[]): thisRuns 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[]): thisRuns 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)[]): thiswithAdminServer
withAdminServer(admin: Tm1AdminServerContainer): thisRegisters 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 | undefinedThe Admin Server set with withAdminServer; undefined if this container runs its own.
getCognos
getCognos(): CognosContainer | undefinedThe Cognos set with withCamSecurity; undefined if TM1 uses its own (native) security.
getCamNamespace
getCamNamespace(): CognosContainer.Namespace | undefinedThe 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(): stringThe 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): thisFails startup unless the server reports exactly this version.
getSource
getSource(): Tm1SourceWhere TM1 comes from.
getRestUrl
getRestUrl(): stringThe REST API's service root as seen from the host, e.g. http://localhost:54321/api/v1/.
getUsername
getUsername(): stringThe TM1 user name tests should log in as; admin unless set.
getPassword
getPassword(): stringThe password for getUsername; empty unless set.
getTm1Version
getTm1Version(): Tm1VersionThe 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.
mountSource
staticstatic mountSource( source: Tm1Source, bind: (source: string, target: string, readOnly: boolean) => void, withEnv: (name: string, value: string) => void, ): voidMounts 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
staticstatic defaultImage(source: Tm1Source): stringThe 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
staticstatic imageFor(setting: string, image: string): string@internal
imageTag
staticstatic imageTag(libraryVersion: string): stringReleased 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(): stringThe 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 | undefinedThe 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(): booleanWhether 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(): StartedTestContainerThe started container.
Throws
- IllegalStateException if it isn't started
isRunning
isRunning(): booleangetHost
getHost(): stringThe host its ports are mapped on.
getContainerId
getContainerId(): stringThe Docker container's ID.
getMappedPort
getMappedPort(port: number): numberThe host port port is mapped to.
withEnv
withEnv(name: string, value: string): thisSets an environment variable, or several.
withEnv
withEnv(variables: Readonly<Record<string, string>> | ReadonlyMap<string, string>): thisSets several environment variables at once.
withEnv
withEnv(name: string | Readonly<Record<string, string>> | ReadonlyMap<string, string>, value?: string): thiswithCommand
withCommand(...commandParts: string[]): thisRuns commandParts in place of the image's command.
withExposedPorts
withExposedPorts(...ports: number[]): thisExposes ports on the Docker host, each on a free port.
withNetwork
withNetwork(network: Network | undefined): thisJoins network (created when the first container on it starts).
withNetworkAliases
withNetworkAliases(...aliases: string[]): thisAdds names it's reached by on getNetwork.
dependsOn
dependsOn(...startables: Startable[]): thisStarts startables before it.
withExtraHost
withExtraHost(host: string, ipAddress: string): thisAdds an /etc/hosts entry.
withHostname
withHostname(hostname: string): thisSets the container's host name.
withReuse
withReuse(reusable: boolean): thisKeeps 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): thisAdds a Docker label.
withCopyFileToContainer
withCopyFileToContainer(hostPath: string, containerPath: string): thisCopies a host file or folder into the container before it starts.
withStartupTimeout
withStartupTimeout(timeout: number): thisHow 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.