ORE Studio 0.0.4
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
test_database_manager Class Reference

Manages test tenant isolation for parallel test execution. More...

#include <test_database_manager.hpp>

Collaboration diagram for test_database_manager:
Collaboration graph

Static Public Member Functions

static database::context make_context ()
 Creates a database context from environment variables.
 
static database::database_options make_database_options ()
 Creates database options from environment variables.
 
static std::string generate_test_tenant_code (const std::string &test_suite_name)
 Generates a unique tenant code for this test run.
 
static std::string provision_test_tenant (database::context &ctx, const std::string &tenant_code, const std::string &description)
 Provisions a test tenant using the SQL provisioner function.
 
static void terminate_test_tenant (database::context &ctx, const std::string &tenant_id)
 Terminates a test tenant using the SQL terminator function.
 
static void set_test_tenant_id_env (const std::string &tenant_id)
 Sets the ORES_TEST_DB_TENANT_ID environment variable.
 
static std::string get_test_tenant_id_env ()
 Gets the test tenant ID from environment variable.
 

Static Public Attributes

static constexpr auto system_tenant_id
 System tenant ID constant (max UUID per RFC 9562).
 

Detailed Description

Manages test tenant isolation for parallel test execution.

This class provides utilities for provisioning and deprovisioning test tenants. Each test suite gets its own isolated tenant, allowing multiple test processes to run concurrently without interference.

Tenant isolation uses PostgreSQL Row Level Security (RLS) to ensure complete data separation between test suites.

Member Function Documentation

◆ generate_test_tenant_code()

std::string generate_test_tenant_code ( const std::string &  test_suite_name)
static

Generates a unique tenant code for this test run.

The tenant code includes the test suite name and timestamp: {test_suite}_{YYYYMMDD}_{HHMMSS}_{pid}_{random}

Parameters
test_suite_nameName of the test suite (e.g., "ores.cli.tests")
Returns
A unique tenant code string
Here is the caller graph for this function:

◆ provision_test_tenant()

std::string provision_test_tenant ( database::context ctx,
const std::string &  tenant_code,
const std::string &  description 
)
static

Provisions a test tenant using the SQL provisioner function.

Creates a new tenant with all required base data (permissions, roles, refdata) copied from the system tenant. The caller must have a valid database context with system tenant access.

Parameters
ctxThe database context to use
tenant_codeThe unique tenant code
descriptionHuman-readable description (e.g., test suite name + version)
Returns
The UUID of the created tenant as a string
Exceptions
std::runtime_errorif provisioning fails
Here is the caller graph for this function:

◆ terminate_test_tenant()

void terminate_test_tenant ( database::context ctx,
const std::string &  tenant_id 
)
static

Terminates a test tenant using the SQL terminator function.

Marks the tenant as terminated but preserves all data for analysis. Use this after unit tests to allow debugging while preventing further use of the tenant. The caller must have system tenant context.

For complete data deletion, use ores_iam_purge_tenant_fn directly.

Parameters
ctxThe database context to use
tenant_idThe UUID of the tenant to terminate
Here is the caller graph for this function:

◆ set_test_tenant_id_env()

void set_test_tenant_id_env ( const std::string &  tenant_id)
static

Sets the ORES_TEST_DB_TENANT_ID environment variable.

This allows tests to retrieve the test tenant ID.

Parameters
tenant_idThe tenant ID to set
Here is the caller graph for this function:

◆ get_test_tenant_id_env()

std::string get_test_tenant_id_env ( )
static

Gets the test tenant ID from environment variable.

Returns
The tenant ID, or empty string if not set
Here is the caller graph for this function:

Member Data Documentation

◆ system_tenant_id

constexpr auto system_tenant_id
staticconstexpr
Initial value:
=
"ffffffff-ffff-ffff-ffff-ffffffffffff"

System tenant ID constant (max UUID per RFC 9562).