skipcheck

TM1 Testcontainers · Docs · Where TM1 comes from

Tm1Source

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

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

Where a Tm1ServerContainer gets TM1 Server from.

The tm1-server image contains no IBM software, so every container needs one of these. They mirror the image's own sources (see the image's README).

discover finds one from the environment, so tests don't hard-code paths. Each setting is read first as a system property and then as an environment variable, under the same name. The names match the tm1-server compose settings, so a .env that works for compose also works for tests. The first source found wins, in this order:

  1. TM1_PRIVATE_IMAGE: an image with TM1 built in (PrivateImage)
  2. TM1_HOME_DIR: an installed tm1_64 folder (InstallDir)
  3. TM1_INSTALL_VOLUME: a Docker volume holding an install (InstallVolume)
  4. TM1_BUNDLE_DIR, optionally with TM1_BUNDLE: a folder holding IBM's bundle, and the file name to use from it (Bundle)
  5. TM1_BUNDLE_URL, optionally with TM1_BUNDLE_SHA256: a download link for the bundle (BundleUrl)

Most tests let discover find the source, so each developer and CI system can supply TM1 their own way:

// From TM1_HOME_DIR, TM1_BUNDLE_DIR and the like; undefined if none is set
const source = Tm1Source.discover();
if (!source) throw new Error("Set TM1_HOME_DIR or TM1_BUNDLE_DIR");
return new Tm1ServerContainer(source);

A test that needs a particular TM1 chooses it in code:

// An installed tm1_64 folder, mounted read-only: nothing to install
const installed = new Tm1Source.InstallDir("/opt/ibm/tm1_64");
// IBM's bundle, installed once into a shared cache volume; with no file named, the newest
const bundle = new Tm1Source.Bundle("/downloads/ibm");
// A download link, such as a pre-signed S3 URL, and optionally its SHA-256
const link = new Tm1Source.BundleUrl("https://downloads.example.com/tm1server.tar.gz", "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
// An image with TM1 inside, from a private registry: it contains IBM software
const image = new Tm1Source.PrivateImage("registry.example.com/tm1-server:11.8.03500.6");
return [installed, bundle, link, image];

A test setup with its own configuration reads the same settings from it with discover:

// The same settings, read from the test setup's own configuration
const source = Tm1Source.discover((name) => testSettings[name]);
if (!source) throw new Error("No TM1 source in the test settings");
return source;

Members

PRIVATE_IMAGE propertySettings read by Tm1Source.discover, in the order they're tried.
HOME_DIR propertyAn installed tm1_64 folder, for Tm1Source.InstallDir.
INSTALL_VOLUME propertyA Docker volume holding an install, for Tm1Source.InstallVolume.
BUNDLE_DIR propertyA folder holding IBM's bundle, for Tm1Source.Bundle.
BUNDLE propertyThe bundle's file name within Tm1Source.BUNDLE_DIR; the newest one if unset.
BUNDLE_URL propertyA download link for IBM's bundle, for Tm1Source.BundleUrl.
BUNDLE_SHA256 propertyThe SHA-256 to check the Tm1Source.BUNDLE_URL download against; optional.
describeA short description for logs and messages.
toStringThe description (describe), for logs.
[inspect.custom]As toString.
discover staticFinds a source using lookup to read each setting (environment variables by default).

PRIVATE_IMAGE

property
static PRIVATE_IMAGE

Settings read by Tm1Source.discover, in the order they're tried.

HOME_DIR

property
static HOME_DIR

An installed tm1_64 folder, for Tm1Source.InstallDir.

INSTALL_VOLUME

property
static INSTALL_VOLUME

A Docker volume holding an install, for Tm1Source.InstallVolume.

BUNDLE_DIR

property
static BUNDLE_DIR

A folder holding IBM's bundle, for Tm1Source.Bundle.

BUNDLE

property
static BUNDLE

The bundle's file name within Tm1Source.BUNDLE_DIR; the newest one if unset.

BUNDLE_URL

property
static BUNDLE_URL

A download link for IBM's bundle, for Tm1Source.BundleUrl.

BUNDLE_SHA256

property
static BUNDLE_SHA256

The SHA-256 to check the Tm1Source.BUNDLE_URL download against; optional.

describe

describe(): string

A short description for logs and messages. Never includes a URL's query string.

toString

toString(): string

The description (describe), for logs.

[inspect.custom]

[inspect.custom](): string

As toString: console.log never shows a URL's secrets either.

discover

static
static discover(lookup: Lookup = Settings.get): Tm1Source | undefined

Finds a source using lookup to read each setting (environment variables by default). Blank values count as unset.

Returns

the first source found, or undefined if none is configured

Throws

IllegalArgumentException if a setting is present but invalid, such as a folder that doesn't exist. A wrong setting fails rather than silently skipping the tests.