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

objectstoretest

package
v1.261028.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package objectstoretest provides an in-process, path-style S3-compatible server for tests that exercise the signing sync object storage backend. It implements only the operations that backend uses and honors the If-Match and If-None-Match conditions, so tests never dial a real bucket.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Method      string
	Key         string
	IfMatch     string
	IfNoneMatch string
	Status      int
}

Request records one request the server received.

type Server

type Server struct {
	// Bucket is the only bucket the server accepts.
	Bucket string
	// HTTP is the underlying TLS test server.
	HTTP *httptest.Server
	// PageSize bounds ListObjectsV2 pages so tests can cover pagination.
	PageSize int
	// BeforeRequest may return a non-zero HTTP status to fail a request
	// before it is applied, simulating a provider or network failure.
	BeforeRequest func(method, key string) int
	// OmitPutETag reports whether a successful PUT response omits its ETag,
	// as some S3-compatible services do.
	OmitPutETag func(key string) bool
	// AfterRequest runs after a request was applied, while no lock is held,
	// so a test can simulate a concurrent writer between two requests.
	AfterRequest func(method, key string)
	// contains filtered or unexported fields
}

Server is a fake S3 bucket served over TLS.

func New

func New(t testing.TB, bucket string) *Server

New starts a fake bucket that is closed when the test ends.

func (*Server) Keys

func (s *Server) Keys() []string

Keys returns every stored key in lexical order.

func (*Server) Mutations

func (s *Server) Mutations() []Request

Mutations returns the PUT and DELETE requests the server received.

func (*Server) Object

func (s *Server) Object(key string) ([]byte, bool)

Object returns a stored object's content.

func (*Server) Put

func (s *Server) Put(key string, content []byte)

Put stores an object directly, as another writer would.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns every request the server received.

func (*Server) UseAsAWSEnvironment

func (s *Server) UseAsAWSEnvironment(t testing.TB)

UseAsAWSEnvironment points the standard AWS SDK environment at this server: it trusts the server certificate, supplies static test credentials, and isolates shared configuration so no test reads the operator's profiles.

Jump to

Keyboard shortcuts

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