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 ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
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) ConnectionString ¶
ConnectionString returns the HTTP endpoint for the S3 API.
type Option ¶
type Option func(*options) error
Option configures Garage-specific settings.
func WithRegion ¶
WithRegion sets the S3 region. The default is "garage".
func (Option) Customize ¶
func (o Option) Customize(*testcontainers.GenericContainerRequest) error
Customize implements testcontainers.ContainerCustomizer. Options are applied by Run.