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

s3test

package
v2.68.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package s3test provides a lightweight in-memory S3-compatible server for unit tests, backed by gofakes3 over an httptest.Server.

Use New to start a server. It is automatically shut down when the test completes. Point an objectstore S3 config at it via Server.Endpoint:

srv := s3test.New(t)
client, err := objectstore.NewWithConfig(&objectstore.Config{
    Backend:    objectstore.BackendS3,
    Bucket: "my-bucket",
    Endpoint:   srv.Endpoint(),
    Region:     s3test.Region,
    PathStyle:  true,
    S3Credentials: &objectstore.S3Credentials{
        AccessKeyID:     s3test.AccessKeyID,
        SecretAccessKey: s3test.SecretAccessKey,
    },
})

Index

Constants

View Source
const (
	AccessKeyID     = "test"
	SecretAccessKey = "test"
	Region          = "us-east-1"
)

Dummy credentials and region for the in-memory server. gofakes3 does not verify signatures, but the AWS SDK still requires a credential and region to construct a client, so tests pass these through.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an in-memory S3-compatible server backed by gofakes3.

func New

func New(tb testing.TB) *Server

New starts an in-memory S3 server and registers tb.Cleanup to shut it down when the test completes. Buckets are created automatically on first use, so tests need not provision them up front.

func (*Server) Backend

func (s *Server) Backend() gofakes3.Backend

Backend returns the underlying gofakes3.Backend for tests that need to seed or inspect objects directly without going through the S3 client.

func (*Server) Endpoint

func (s *Server) Endpoint() string

Endpoint returns the base URL of the in-memory server. Pass this as [objectstore.Config.Endpoint] along with PathStyle=true, since the server does not support virtual-host bucket addressing.

Jump to

Keyboard shortcuts

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