s3mock

package module
v0.0.0-...-ea854ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package s3mock provides a testcontainers module for Adobe S3Mock, a lightweight server that implements the AWS S3 API. Use it in tests to interact with S3 buckets and objects without real AWS credentials or network access.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithInitialBuckets

func WithInitialBuckets(buckets ...string) testcontainers.CustomizeRequestOption

WithInitialBuckets returns an option that configures S3Mock to pre-create the given buckets on startup. Calling it with no arguments is a no-op. Both the 3.x/4.x env var (domain prefix) and the 5.x+ env var (store prefix) are set so that the option works across all supported S3Mock versions.

Types

type Container

type Container struct {
	testcontainers.Container
}

Container represents the S3Mock container type used in the module. It wraps the generic testcontainers.Container and exposes S3Mock-specific helper methods for retrieving the HTTP and HTTPS endpoint URLs.

func Run

Run creates and starts an S3Mock container using the given image and options. The container exposes HTTP on port 9090 and HTTPS on port 9191, and waits until the /favicon.ico health path returns HTTP 200 before returning.

Example

ExampleRun demonstrates how to start an S3Mock container with a pre-created bucket and configure the AWS SDK v2 client to point at the container endpoint.

// runS3MockContainer {
ctx := context.Background()

s3mockContainer, err := s3mock.Run(ctx,
	"adobe/s3mock:3.9.1",
	s3mock.WithInitialBuckets("mybucket"),
)
defer func() {
	if s3mockContainer != nil {
		if err := testcontainers.TerminateContainer(s3mockContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}
}()
if err != nil {
	log.Printf("failed to start container: %s", err)
	return
}
// }

// awsClientSetup {
endpointURL, err := s3mockContainer.EndpointURL(ctx)
if err != nil {
	log.Printf("failed to get endpoint URL: %s", err)
	return
}

awsCfg, err := config.LoadDefaultConfig(ctx,
	config.WithRegion("us-east-1"),
	config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test", "test", "")),
)
if err != nil {
	log.Printf("failed to load AWS config: %s", err)
	return
}

client := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
	o.EndpointResolverV2 = &s3EndpointResolver{endpointURL: endpointURL}
	o.UsePathStyle = true
})
// }

out, err := client.ListBuckets(ctx, &s3.ListBucketsInput{})
if err != nil {
	log.Printf("failed to list buckets: %s", err)
	return
}

fmt.Println(len(out.Buckets))
Output:
1

func (*Container) EndpointURL

func (c *Container) EndpointURL(ctx context.Context) (string, error)

EndpointURL returns the HTTP endpoint URL for the S3Mock container, using the dynamically mapped host port for container port 9090.

func (*Container) HTTPSEndpointURL

func (c *Container) HTTPSEndpointURL(ctx context.Context) (string, error)

HTTPSEndpointURL returns the HTTPS endpoint URL for the S3Mock container, using the dynamically mapped host port for container port 9191.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL