s3stub

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package s3stub is an S3 endpoint for tests (ADR-0203, ADR-0208): path-style object PUT, GET, HEAD, DELETE and CopyObject, ListObjectsV2 and ListObjectVersions over an in-memory bucket stamped by a manual clock, with the bucket's versioning and Object Lock answers set by the test.

Index

Constants

View Source
const Bucket = "funcd-backup"

Bucket is the stub's bucket name.

View Source
const Drop = -1

Drop as a Status closes the connection without an answer.

Variables

This section is empty.

Functions

func CredentialsFile

func CredentialsFile(t testing.TB, keyID string) string

CredentialsFile writes an AWS shared credentials file whose [default] profile holds keyID.

func Main

func Main(m *testing.M)

Main keeps the AWS SDK off the developer's shared config and credentials and the EC2 metadata service for the process, so tests using the stub need no t.Setenv and can run in parallel: call it from TestMain.

Types

type Condition

type Condition int

Condition is how the stub answers a put with If-None-Match: *.

const (
	Honored Condition = iota
	Ignored
	Refused
)

type Stub

type Stub struct {
	Clock *clock.Manual

	Cond             Condition
	Box              bool
	FailPut          func(key string) bool
	OnPut            func(s *Stub, key string)
	Versioning       string
	VersioningStatus int
	ObjectLock       bool
	LockStatus       int
	// contains filtered or unexported fields
}

Stub is the endpoint. Set its fields through Set. Box refuses every object read and delete and every put under gen/verified/, as ADR-0203's box policy does; FailPut refuses chosen puts and copies; OnPut runs after each stored put, under the stub's lock (use PutLocked there). Versioning is the bucket's status ("", "Enabled", "Suspended"); VersioningStatus and LockStatus, when set, answer that read with the HTTP status (or Drop).

func New

func New(t testing.TB, c *clock.Manual) *Stub

New starts a stub stamped by c; a nil c is a manual clock at the current time.

func (*Stub) Endpoint

func (s *Stub) Endpoint() string

Endpoint is the stub's HTTP endpoint.

func (*Stub) ExpireNoncurrentLocked

func (s *Stub) ExpireNoncurrentLocked(key string)

ExpireNoncurrentLocked drops every version of key but the current one, as a noncurrent-version expiry rule does; call it under the stub's lock.

func (*Stub) Keys

func (s *Stub) Keys(prefix string) []string

Keys returns the current keys under prefix, sorted.

func (*Stub) Object

func (s *Stub) Object(key string) (data []byte, contentType string, meta map[string]string, ok bool)

Object returns key's current bytes, content type and metadata.

func (*Stub) PutKeys

func (s *Stub) PutKeys(prefix string) []string

PutKeys returns the stored puts under prefix, in order.

func (*Stub) PutLocked

func (s *Stub) PutLocked(key string, data []byte)

PutLocked stores an object; call it under the stub's lock (from OnPut or Set).

func (*Stub) Seed

func (s *Stub) Seed(key string, data []byte)

Seed stores an object as another writer would, unrecorded in the puts.

func (*Stub) Seen

func (s *Stub) Seen() (requests, auth []string)

Seen returns every request ("<method> <key>", a sub-resource as "?<name>") and its Authorization header.

func (*Stub) ServeHTTP

func (s *Stub) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Stub) Set

func (s *Stub) Set(f func(s *Stub))

Set changes the stub under its lock.

func (*Stub) SetSize

func (s *Stub) SetSize(key string, size int64)

SetSize makes key's current version list with size bytes, for a test of a size limit.

func (*Stub) URL

func (s *Stub) URL(params ...string) string

URL is the stub's bucket URL; params are added to its query (prefix=p/ for one).

func (*Stub) VersionCount

func (s *Stub) VersionCount(key string) int

VersionCount returns how many versions and delete markers key has.

Jump to

Keyboard shortcuts

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