Skip to content

FakeGCSServer

Since v0.44.0

Introduction

The Testcontainers module for FakeGCSServer provides a Google Cloud Storage API emulator for local development and testing. It runs fsouza/fake-gcs-server and exposes the GCS JSON API on port 4443 with an in-memory storage backend.

Adding this module to your project dependencies

Please run the following command to add the FakeGCSServer module to your Go dependencies:

go get github.com/testcontainers/testcontainers-go/modules/fakegcsserver

Usage example

ctx := context.Background()

fakegcsserverContainer, err := fakegcsserver.Run(ctx, "fsouza/fake-gcs-server:1.56.1")
defer func() {
    if err := testcontainers.TerminateContainer(fakegcsserverContainer); err != nil {
        log.Printf("failed to terminate container: %s", err)
    }
}()
if err != nil {
    log.Printf("failed to start container: %s", err)
    return
}

When connecting with the Google Cloud Storage client library, set the STORAGE_EMULATOR_HOST environment variable in your tests:

storageURL, err := ctr.StorageURL(ctx)
// storageURL is e.g. "http://localhost:4443/storage/v1"

t.Setenv("STORAGE_EMULATOR_HOST", storageURL)

Module Reference

Run function

The FakeGCSServer module exposes one entrypoint function to create the FakeGCSServer container, and this function receives three parameters:

func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
  • context.Context, the Go context.
  • string, the Docker image to use.
  • testcontainers.ContainerCustomizer, a variadic argument for passing options.

Image

Use the second argument in the Run function to set a valid Docker image. In example: Run(context.Background(), "fsouza/fake-gcs-server:1.56.1").

Image compatibility on AMD64

Use fsouza/fake-gcs-server:1.56.1, which includes a native AMD64 binary. The 1.47 image ships a 32-bit binary in its AMD64 variant. On Docker 29.4.2, the default seccomp profile blocks the socketcall syscall used by that binary, causing startup to fail with socket: function not implemented. Updating the image avoids this issue; upgrading Docker to 29.4.3 or later also restores support for the syscall. See the runner image issue for details.

Container Options

When starting the FakeGCSServer container, you can pass options in a variadic way to configure it.

WithScheme

Sets the HTTP scheme used by the fake-gcs-server. Valid values are "http" (default) and "https".

fakegcsserver.Run(ctx, "fsouza/fake-gcs-server:1.56.1",
    fakegcsserver.WithScheme("https"),
)

The following options are exposed by the testcontainers package.

Basic Options

Lifecycle Options

Files & Mounts Options

Build Options

Logging Options

Image Options

Networking Options

Advanced Options

Experimental Options

Container Methods

The FakeGCSServer container exposes the following methods:

StorageURL

Returns the GCS-compatible storage URL for the container. The URL format is <scheme>://<host>:<port>/storage/v1, where scheme matches the value passed to WithScheme (default "http").

storageURL, err := ctr.StorageURL(ctx)