Help us shape the future of Go! Take the 2026 Go Developer Survey

garage

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

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package garage provides a Testcontainers module for Garage, an S3-compatible object store.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBucket

func WithBucket(bucket string) testcontainers.CustomizeRequestOption

WithBucket sets the bucket created at startup. The default is "testcontainers".

func WithCredentials

func WithCredentials(accessKey, secretKey string) testcontainers.CustomizeRequestOption

WithCredentials sets the initial S3 access key ID and secret access key. Garage requires at least 8 bytes for the access key and 16 bytes for the secret key.

Types

type Container

type Container struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

Container represents a single-node Garage container.

func Run

Run starts a single-node Garage server with an initial access key and bucket. The image must support the bootstrap flags introduced in Garage v2.3.0.

Example

ExampleRun connects an AWS SDK client to the initial Garage bucket.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/credentials"
	"github.com/aws/aws-sdk-go-v2/service/s3"

	"github.com/testcontainers/testcontainers-go"
	"github.com/testcontainers/testcontainers-go/modules/garage"
)

func main() {
	ctx := context.Background()
	garageContainer, err := garage.Run(ctx, "dxflrs/garage:v2.4.1")
	defer func() {
		if err := testcontainers.TerminateContainer(garageContainer, testcontainers.StopTimeout(0)); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}
	endpoint, err := garageContainer.ConnectionString(ctx)
	if err != nil {
		log.Printf("failed to get endpoint: %s", err)
		return
	}
	client := s3.New(s3.Options{
		BaseEndpoint: aws.String(endpoint),
		Region:       garageContainer.Region(),
		Credentials:  credentials.NewStaticCredentialsProvider(garageContainer.AccessKey(), garageContainer.SecretKey(), ""),
		UsePathStyle: true,
	})
	_, err = client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: aws.String(garageContainer.Bucket())})
	fmt.Println(err == nil)
}
Output:
true

func (*Container) AccessKey

func (c *Container) AccessKey() string

AccessKey returns the initial S3 access key ID.

func (*Container) Bucket

func (c *Container) Bucket() string

Bucket returns the bucket created during startup.

func (*Container) ConnectionString

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

ConnectionString returns the HTTP endpoint for the S3 API.

func (*Container) Region

func (c *Container) Region() string

Region returns the S3 region.

func (*Container) SecretKey

func (c *Container) SecretKey() string

SecretKey returns the initial S3 secret access key.

type Option

type Option func(*options) error

Option configures Garage-specific settings.

func WithRegion

func WithRegion(region string) Option

WithRegion sets the S3 region. The default is "garage".

func (Option) Customize

Customize implements testcontainers.ContainerCustomizer. Options are applied by Run.

Jump to

Keyboard shortcuts

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