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 static | The image TM1 runs in, without its tag (the library's version, or edge). |
ServerImage static | The setting that replaces DefaultImage (a mirror, a local build). |
RestPort static | TM1's REST port. |
CacheVolume static | 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 | TM1 from source, in the image DefaultImageFor picks. |
Tm1ServerContainer constructor | TM1 from source, in image. |
SharedAsync static | The one TM1 server the tests of a run share, started the first time from the discovered source (Tm1Source.Discover), with reuse. |
WithSeed | Starts with seed's database, and logs in with its login. |
WithData | Starts with the database in dataDir, copied into the container; set its login with WithCredentials. |
WithCredentials | The login to check the server with and to hand to tests. |
WithCamSecurity | 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 | As WithCamSecurity, in namespace. |
WithAdminServer | Registers TM1 with a shared Admin Server, on its network, rather than its own. |
AdminServer property | The shared Admin Server, or null for TM1's own. |
Cognos property | The Cognos TM1 is in CAM security with, or null for TM1's own security. |
CamNamespace property | The CAM namespace, or null without Cognos. |
Authorization property | The Authorization header that logs in as Username. |
WithExpectedVersion | Refuses to start unless the server reports version. |
Source property | Where TM1 comes from. |
RestUrl property | The REST API's root, http://host:port/api/v1/. |
Username property | The login. |
Password property | The login's password. |
Tm1Version property | The version the started server reports. |
DefaultImageFor static | The image for source. |
DockerImageName property | The image it runs. |
EnvMap property | Its environment variables, so far. |
CommandParts property | The command it runs, if not the image's. |
ExposedPorts property | The ports it exposes on the Docker host. |
Network property | The network it joins, or null for Docker's default bridge. |
NetworkAliases property | Its names on Network. |
Dependencies property | What starts before it. |
Container property | The started container. |
IsRunning property | |
Host property | The host its ports are mapped on. |
ContainerId property | The Docker container's ID. |
GetMappedPort | The host port port is mapped to. |
WithEnv | Sets an environment variable. |
WithEnv | Sets environment variables. |
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 Network. |
DependsOn | Starts startables before it. |
WithExtraHost | Adds an /etc/hosts entry. |
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. |
WithCopyFileToContainer | Copies a host file or folder into the container before it starts. |
WithStartupTimeout | How long to wait for it to be ready. |
StartAsync | |
StopAsync | |
DisposeAsync | Stops it. |
GetLogsAsync | Its log, so far. |
DefaultImage
staticconst string DefaultImageThe image TM1 runs in, without its tag (the library's version, or edge).
ServerImage
staticconst string ServerImageThe setting that replaces DefaultImage (a mirror, a local build).
RestPort
staticconst int RestPortTM1's REST port.
CacheVolume
staticconst string CacheVolumeThe volume bundles are unpacked into, shared by every run (and with the Java, Python and .NET tests), so a bundle is unpacked once.
Tm1ServerContainer
constructorTm1ServerContainer(Tm1Source source)TM1 from source, in the image DefaultImageFor picks.
Tm1ServerContainer
constructorTm1ServerContainer(string image, Tm1Source source)TM1 from source, in image.
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
propertyTm1AdminServerContainer? AdminServerThe shared Admin Server, or null for TM1's own.
Cognos
propertyCognosContainer? CognosThe Cognos TM1 is in CAM security with, or null for TM1's own security.
CamNamespace
propertyCognosContainer.Namespace? CamNamespaceThe CAM namespace, or null without Cognos.
Authorization
propertystring AuthorizationThe Authorization header that logs in as Username.
WithExpectedVersion
Tm1ServerContainer WithExpectedVersion(Tm1Version version)Refuses to start unless the server reports version.
Source
propertyTm1Source SourceWhere TM1 comes from.
RestUrl
propertystring RestUrlThe REST API's root, http://host:port/api/v1/.
Username
propertystring UsernameThe login.
Password
propertystring PasswordThe login's password.
Tm1Version
propertyTm1Version Tm1VersionThe version the started server reports.
Throws
InvalidOperationException- It isn't started.
DefaultImageFor
staticstring 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
propertystring DockerImageNameThe image it runs.
EnvMap
propertyIReadOnlyDictionary<string, string> EnvMapIts environment variables, so far.
CommandParts
propertyIReadOnlyList<string> CommandPartsThe command it runs, if not the image's.
ExposedPorts
propertyIReadOnlyList<int> ExposedPortsThe ports it exposes on the Docker host.
Network
propertyNetwork? NetworkThe network it joins, or null for Docker's default bridge.
NetworkAliases
propertyIReadOnlyList<string> NetworkAliasesIts names on Network.
Dependencies
propertyIReadOnlyCollection<IStartable> DependenciesWhat starts before it.
Container
propertyIContainer ContainerThe started container.
Throws
InvalidOperationException- It isn't started.
IsRunning
propertybool IsRunningHost
propertystring HostThe host its ports are mapped on.
ContainerId
propertystring ContainerIdThe 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.