skipcheck

TM1 Testcontainers · Docs · Containers

Tm1ServerContainer

using 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 RequiresTm1FactAttribute, 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 Tm1Version. 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.RestUrl).BasicAuth(server.Username, server.Password).Build();

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

var source = Tm1Source.Discover() ?? throw new InvalidOperationException("Set TM1_HOME_DIR or TM1_BUNDLE_DIR");
// SData's login is admin / apple, and the server must be this version
await using var server = new Tm1ServerContainer(source).WithSeed(Tm1Seed.Sdata).WithExpectedVersion(Tm1Version.Parse("11.8.03500.6"));
await server.StartAsync();
// Declared after the server, so the client closes before the container stops
await using var tm1 = Tm1Client.Builder().BaseUrl(server.RestUrl).BasicAuth(server.Username, server.Password).Build();
// SData's cubes, such as SalesCube
return await tm1.Cubes.ModelCubesAsync(ODataQuery.None().Select(Cube.Fields.Name)).Select(cube => cube.Name!).ToListAsync();

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 var server = new Tm1ServerContainer(source).WithData("TestData/tm1/sales").WithCredentials("admin", "apple"); // a login the database has
await server.StartAsync();
return server.RestUrl; // http://localhost:54321/api/v1/

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

await using var cognos = new CognosContainer(cognosSource).WithUser("admin", "adminpw", "Admins").WithUser("viewer", "viewerpw", "Readers");
await using var server = new Tm1ServerContainer(tm1Source).WithCamSecurity(cognos, "admin");
await server.StartAsync(); // starts Cognos first
// Each test user logs in with their own identity, through the LDAP namespace
await using var viewer = Tm1Client
    .Builder()
    .BaseUrl(server.RestUrl)
    .Authenticator(Tm1Authenticator.CamNamespace("viewer", "viewerpw", CognosContainer.NamespaceId))
    .Build();
// TM1 knows the user by their CAMID
return (await viewer.Users.ActiveUserAsync(ODataQuery.None().Select(User.Fields.Name))).Name;

Members

DefaultImage staticThe image TM1 runs in, without its tag (the library's version, or edge).
ServerImage staticThe setting that replaces DefaultImage (a mirror, a local build).
RestPort staticTM1's REST port.
CacheVolume staticThe volume bundles are unpacked into, shared by every run (and with the Java, Python and .NET tests), so a bundle is unpacked once.
Tm1ServerContainer constructorTM1 from source, in the image DefaultImageFor picks.
Tm1ServerContainer constructorTM1 from source, in image.
SharedAsync staticThe one TM1 server the tests of a run share, started the first time from the discovered source (Tm1Source.Discover), with reuse.
WithSeedStarts with seed's database, and logs in with its login.
WithDataStarts with the database in dataDir, copied into the container; set its login with WithCredentials.
WithCredentialsThe login to check the server with and to hand to tests.
WithCamSecurityPuts TM1 in CAM security (mode 5) with cognos's LDAP namespace, its test users admins TM1 administrators; it logs in as the first.
WithCamSecurityAs WithCamSecurity, in namespace.
WithAdminServerRegisters TM1 with a shared Admin Server, on its network, rather than its own.
AdminServer propertyThe shared Admin Server, or null for TM1's own.
Cognos propertyThe Cognos TM1 is in CAM security with, or null for TM1's own security.
CamNamespace propertyThe CAM namespace, or null without Cognos.
Authorization propertyThe Authorization header that logs in as Username.
WithExpectedVersionRefuses to start unless the server reports version.
Source propertyWhere TM1 comes from.
RestUrl propertyThe REST API's root, http://host:port/api/v1/.
Username propertyThe login.
Password propertyThe login's password.
Tm1Version propertyThe version the started server reports.
DefaultImageFor staticThe image for source.
DockerImageName propertyThe image it runs.
EnvMap propertyIts environment variables, so far.
CommandParts propertyThe command it runs, if not the image's.
ExposedPorts propertyThe ports it exposes on the Docker host.
Network propertyThe network it joins, or null for Docker's default bridge.
NetworkAliases propertyIts names on Network.
Dependencies propertyWhat starts before it.
Container propertyThe started container.
IsRunning property
Host propertyThe host its ports are mapped on.
ContainerId propertyThe Docker container's ID.
GetMappedPortThe host port port is mapped to.
WithEnvSets an environment variable.
WithEnvSets environment variables.
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 Network.
DependsOnStarts startables before it.
WithExtraHostAdds an /etc/hosts entry.
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.
WithCopyFileToContainerCopies a host file or folder into the container before it starts.
WithStartupTimeoutHow long to wait for it to be ready.
StartAsync
StopAsync
DisposeAsyncStops it.
GetLogsAsyncIts log, so far.

DefaultImage

static
const string DefaultImage

The image TM1 runs in, without its tag (the library's version, or edge).

ServerImage

static
const string ServerImage

The setting that replaces DefaultImage (a mirror, a local build).

RestPort

static
const int RestPort

TM1's REST port.

CacheVolume

static
const string CacheVolume

The volume bundles are unpacked into, shared by every run (and with the Java, Python and .NET tests), so a bundle is unpacked once.

Tm1ServerContainer

constructor
Tm1ServerContainer(Tm1Source source)

TM1 from source, in the image DefaultImageFor picks.

Tm1ServerContainer

constructor
Tm1ServerContainer(string image, Tm1Source source)

TM1 from source, in image.

SharedAsync

static
Task<Tm1ServerContainer> SharedAsync(CancellationToken cancellationToken = default)

The one TM1 server the tests of a run share, started the first time from the discovered source (Tm1Source.Discover), with reuse.

Throws

InvalidOperationException
No source is configured.

WithSeed

Tm1ServerContainer WithSeed(Tm1Seed seed)

Starts with seed's database, and logs in with its login.

WithData

Tm1ServerContainer WithData(string dataDir)

Starts with the database in dataDir, copied into the container; set its login with WithCredentials.

Throws

ArgumentException
It isn't a folder.

WithCredentials

Tm1ServerContainer WithCredentials(string username, string password)

The login to check the server with and to hand to tests.

WithCamSecurity

Tm1ServerContainer WithCamSecurity(CognosContainer cognos, params string[] admins)

Puts TM1 in CAM security (mode 5) with cognos's LDAP namespace, its test users admins TM1 administrators; it logs in as the first.

WithCamSecurity

Tm1ServerContainer WithCamSecurity(CognosContainer cognos, CognosContainer.Namespace @namespace, params string[] admins)

As WithCamSecurity, in namespace.

Throws

ArgumentException
No admin is named.

WithAdminServer

Tm1ServerContainer WithAdminServer(Tm1AdminServerContainer admin)

Registers TM1 with a shared Admin Server, on its network, rather than its own.

AdminServer

property
Tm1AdminServerContainer? AdminServer

The shared Admin Server, or null for TM1's own.

Cognos

property
CognosContainer? Cognos

The Cognos TM1 is in CAM security with, or null for TM1's own security.

CamNamespace

property
CognosContainer.Namespace? CamNamespace

The CAM namespace, or null without Cognos.

Authorization

property
string Authorization

The Authorization header that logs in as Username.

WithExpectedVersion

Tm1ServerContainer WithExpectedVersion(Tm1Version version)

Refuses to start unless the server reports version.

Source

property
Tm1Source Source

Where TM1 comes from.

RestUrl

property
string RestUrl

The REST API's root, http://host:port/api/v1/.

Username

property
string Username

The login.

Password

property
string Password

The login's password.

Tm1Version

property
Tm1Version Tm1Version

The version the started server reports.

Throws

InvalidOperationException
It isn't started.

DefaultImageFor

static
string DefaultImageFor(Tm1Source source)

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

DockerImageName

property
string DockerImageName

The image it runs.

EnvMap

property
IReadOnlyDictionary<string, string> EnvMap

Its environment variables, so far.

CommandParts

property
IReadOnlyList<string> CommandParts

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

ExposedPorts

property
IReadOnlyList<int> ExposedPorts

The ports it exposes on the Docker host.

Network

property
Network? Network

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

NetworkAliases

property
IReadOnlyList<string> NetworkAliases

Its names on Network.

Dependencies

property
IReadOnlyCollection<IStartable> Dependencies

What starts before it.

Container

property
IContainer Container

The started container.

Throws

InvalidOperationException
It isn't started.

IsRunning

property
bool IsRunning

Host

property
string Host

The host its ports are mapped on.

ContainerId

property
string ContainerId

The Docker container's ID.

GetMappedPort

int GetMappedPort(int port)

The host port port is mapped to.

WithEnv

TSelf WithEnv(string name, string value)

Sets an environment variable.

WithEnv

TSelf WithEnv(IReadOnlyDictionary<string, string> variables)

Sets environment variables.

WithCommand

TSelf WithCommand(params string[] commandParts)

Runs commandParts in place of the image's command.

WithExposedPorts

TSelf WithExposedPorts(params int[] exposedPorts)

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

WithNetwork

TSelf WithNetwork(Network? network)

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

WithNetworkAliases

TSelf WithNetworkAliases(params string[] networkAliases)

Adds names it's reached by on Network.

DependsOn

TSelf DependsOn(params IStartable[] startables)

Starts startables before it.

WithExtraHost

TSelf WithExtraHost(string host, string ipAddress)

Adds an /etc/hosts entry.

WithReuse

TSelf WithReuse(bool reusable)

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.

WithCopyFileToContainer

TSelf WithCopyFileToContainer(string hostPath, string containerPath)

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

WithStartupTimeout

TSelf WithStartupTimeout(TimeSpan timeout)

How long to wait for it to be ready.

StartAsync

Task StartAsync(CancellationToken cancellationToken = default)

StopAsync

Task StopAsync(CancellationToken cancellationToken = default)

DisposeAsync

ValueTask DisposeAsync()

Stops it.

GetLogsAsync

Task<string> GetLogsAsync(CancellationToken cancellationToken = default)

Its log, so far.