Skip to content

[FEAT] Add integration tests against Cosmos DB emulator for Azure templates #53

@colbytimm

Description

@colbytimm

Summary

Currently all tests mock the database layer. Add integration tests that exercise the full Controller → Service → Repository → Database stack against the Azure Cosmos DB Linux emulator running as a Docker service container in GitHub Actions. This validates that the generated repository code actually works against a real Cosmos DB API.

Each language's CI pipeline gets a new integration-test job that starts the emulator, seeds a database/container, and runs repository-level integration tests.

Category: testing, azure

Acceptance Criteria

  • GHA workflow for each language (Python, TypeScript, .NET, Go) adds a test-integration-azure job (runs on ubuntu-latest only)
  • Cosmos DB Linux emulator (mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest) runs as a Docker service container
  • Each template includes an integration_tests/ or tests/integration/ directory with tests that:
    • Connect to the emulator using its well-known account key
    • Create the database and container as test setup
    • Run CRUD operations (create, read, list, update, soft-delete) through the repository layer
    • Assert correct data in the database after each operation
  • Makefile adds a test-integration target
  • Integration tests are skipped when emulator is unavailable (env var guard or connection check)
  • Tests run in CI only on the Azure Function App matrix variant

Implementation Notes

Cosmos DB Emulator in GHA

services:
  cosmosdb:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
    ports:
      - 8081:8081
      - 10250-10255:10250-10255
    env:
      AZURE_COSMOS_EMULATOR_PARTITION_COUNT: 1
      AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: false

Emulator connection details:

  • Endpoint: https://localhost:8081
  • Account Key: Well-known emulator key (C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==)
  • SSL: Self-signed cert (tests need to disable SSL verification or trust the emulator cert)

Test Structure per Language

Each integration test should:

  1. Initialize the database client pointing at the emulator
  2. Create a test database + container in setup/beforeAll
  3. Run each CRUD operation and assert results
  4. Clean up the database in teardown/afterAll

Estimated CI Impact

  • Adds ~2-4 minutes per language (emulator startup + test execution)
  • Only runs on Ubuntu (emulator is Linux-only Docker image)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions