Files
git.stella-ops.org/docs/features/unchecked/tests/testcontainers-integration.md

3.0 KiB

Testcontainers Integration (.NET xUnit)

Module

__Tests

Status

IMPLEMENTED

Description

Testcontainers used for Postgres integration fixtures, router chaos testing, and OCI registry testing with multiple container types.

Implementation Details

  • PostgreSQL Integration Fixture: src/__Tests/__Libraries/StellaOps.Infrastructure.Postgres.Testing/PostgresIntegrationFixture.cs -- Testcontainers-based PostgreSQL fixture that spins up an ephemeral Postgres container for integration tests; manages connection strings, schema migrations, and container lifecycle.
  • Migration Test Attribute: src/__Tests/__Libraries/StellaOps.Infrastructure.Postgres.Testing/MigrationTestAttribute.cs -- xUnit attribute that marks tests requiring a database container, ensuring proper fixture setup and teardown.
  • OCI Distribution Registry Container: src/__Tests/__Libraries/StellaOps.Infrastructure.Registry.Testing/DistributionRegistryContainer.cs -- Testcontainers wrapper for the Docker Distribution (registry:2) container used in OCI push/pull integration tests.
  • Zot Registry Container: src/__Tests/__Libraries/StellaOps.Infrastructure.Registry.Testing/ZotRegistryContainer.cs -- Testcontainers wrapper for the Zot OCI registry, testing compatibility with alternative registry implementations.
  • Harbor Registry Container: src/__Tests/__Libraries/StellaOps.Infrastructure.Registry.Testing/HarborRegistryContainer.cs -- Testcontainers wrapper for Harbor registry, testing enterprise registry features (replication, scanning, RBAC).
  • Schema Evolution Test Base: src/__Tests/__Libraries/StellaOps.Testing.SchemaEvolution/PostgresSchemaEvolutionTestBase.cs -- abstract test base that uses Testcontainers PostgreSQL for running schema migration forward/backward compatibility tests.
  • Network Isolated Test Base: src/__Tests/__Libraries/StellaOps.Testing.AirGap/NetworkIsolatedTestBase.cs -- Testcontainers-based test base that creates network-isolated containers for air-gap scenario testing.

E2E Test Plan

  • Start a PostgresIntegrationFixture, run a migration, insert test data, query it back, and verify the container is properly cleaned up after the test completes
  • Start a DistributionRegistryContainer, push an OCI image, pull it back, and verify the image digest matches
  • Start a ZotRegistryContainer, push an OCI artifact, and verify Zot-specific API compatibility (catalog, tags list)
  • Start a HarborRegistryContainer, push an image, and verify Harbor-specific endpoints (projects, repositories) are accessible
  • Run a PostgresSchemaEvolutionTestBase subclass, apply migrations forward and backward, and verify the Testcontainers Postgres instance is properly provisioned and torn down
  • Run two Testcontainers-based tests in parallel (e.g., Postgres + OCI registry) and verify no port conflicts or container name collisions occur
  • Verify NetworkIsolatedTestBase creates a container with no external network access by attempting an outbound HTTP request and confirming it fails