Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

cloudemu Testcontainers module

Run the cloudemu standalone server in a container for out-of-process integration tests, using Testcontainers-Go.

This is a separate Go module so testcontainers-go (and the Docker client it pulls in) never becomes a dependency of the core cloudemu module.

import (
    "testing"

    cloudemu "github.com/stackshy/cloudemu/v2/contrib/testcontainers"
)

func TestMyApp(t *testing.T) {
    ctx := context.Background()

    ctr, err := cloudemu.Run(ctx) // pulls ghcr.io/stackshy/cloudemu:latest
    if err != nil {
        t.Fatal(err)
    }
    defer ctr.Terminate(ctx)

    endpoint, _ := ctr.AWSEndpoint(ctx) // http://host:mappedPort
    // point aws-sdk-go-v2 at `endpoint` (o.BaseEndpoint), then run your code.

    ctr.Reset(ctx)             // clean slate between tests
    ctr.Seed(ctx, myFixtures)  // load a known baseline (seed.Fixtures or any JSON-able value)
}

Methods: AWSEndpoint, AzureEndpoint, GCPEndpoint, KubernetesEndpoint, Reset, Seed, plus the embedded Testcontainers container (Terminate, …). Pin a version or use a local image with cloudemu.WithImage("...").

cloudemu.WithEnforceAuth(token) starts the server with --enforce-auth and the given admin token (pass "" to have one generated); Reset and Seed send it for you. The flag is appended to any command set by an earlier option. Access key ids must look like real ones (AKIA plus 16 uppercase letters or digits). Seed your first IAM user with a known key ({"iamUsers":[{"name":"admin","accessKeys":[{"accessKeyId":"AKIA...","secretAccessKey":"..."}]}]}) before making signed calls.

The module's own acceptance test builds the image from the repo Dockerfile, so it needs Docker; run it with go test ./... from this directory (skipped under -short).