backendtest

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backendtest provides a shared conformance suite that every backend.Backend implementation must pass, proving the implementations are interchangeable (DESIGN.md §2: "backends are interchangeable behind backend.Backend").

Index

Constants

View Source
const Unknown = int64(-1)

Unknown is the free-bytes/free-inodes value that makes a Capacity report backend.ErrSpaceUnknown for that axis, modeling a backend without the capability.

Variables

View Source
var ErrInjected = errors.New("backendtest: injected write failure")

ErrInjected is the failure Counting injects into a chosen write.

Functions

func AtomicConditionalPut added in v0.33.0

func AtomicConditionalPut(h http.Handler) http.Handler

AtomicConditionalPut wraps an S3-compatible test server's handler, serializing every request that carries an If-None-Match or If-Match precondition. Real S3 evaluates a conditional PUT atomically; the embeddable go-faster/fs server (as of v0.3.0) checks the precondition and performs the write as two separate steps, so two concurrent "If-None-Match: *" PUTs can both observe the key absent and both succeed — a TOCTOU race the conformance suite's single-winner CAS test rightly rejects. Serializing just the conditional requests restores real-S3 semantics for the tests without patching the fake. (Worth fixing upstream; this wrapper is then a no-op.)

func Digest added in v0.49.0

func Digest(tb testing.TB, b backend.Backend, partPrefixes []string) string

Digest renders every object under each of partPrefixes as one sorted "name size sha256" line, the name relative to its part prefix, since that prefix is random. It is the golden-file form of a part set.

func IsPartObject added in v0.49.0

func IsPartObject(key string) bool

IsPartObject reports whether key names an object inside a part directory rather than an engine-level object (the bucket index, the series or stream index).

func PartDirs added in v0.49.0

func PartDirs(ctx context.Context, tb testing.TB, b backend.Backend, enginePrefix string) []string

PartDirs returns the sorted part ids that have objects under enginePrefix. Part ids are minted, so a test cannot name them up front and asserts over this set instead.

func Run

func Run(t *testing.T, factory func(t *testing.T) backend.Backend)

Run executes the full conformance suite against a backend produced by factory — the object operations plus the conditional-write (CAS) [Backend.PutIfAbsent]. Each subtest gets a fresh, empty backend. Call it from each implementation's test package.

func WithoutCapabilities added in v0.49.0

func WithoutCapabilities(b backend.Backend) backend.Backend

WithoutCapabilities wraps b exposing only the backend.Backend methods: every optional capability (backend.Viewer, backend.Sizer, backend.ReaderAt, backend.ObjectCreator, backend.DeferredSyncer, backend.NodeLocal, …) is hidden, so callers take their fallback paths — the shape of a minimal embedder backend.

Types

type ByteCounter added in v0.49.0

type ByteCounter struct {
	backend.Backend
	// contains filtered or unexported fields
}

ByteCounter counts the calls and bytes of every Read, ReadView and ReadAt, in total and per key. It serves backend.Viewer and backend.ReaderAt through backend.ReadView and backend.ReadAt, so an inner backend without them falls back to a whole read, and forwards backend.RangeHinter to say so. Every other capability is hidden, backend.Sizer included: a size probe falls back to a counted Read. SizedByteCounter forwards Size.

func NewByteCounter added in v0.49.0

func NewByteCounter(b backend.Backend) *ByteCounter

NewByteCounter wraps b.

func (*ByteCounter) Bytes added in v0.49.0

func (b *ByteCounter) Bytes() int64

Bytes returns the bytes read since the last ByteCounter.Reset.

func (*ByteCounter) RangesNatively added in v0.49.0

func (b *ByteCounter) RangesNatively(ctx context.Context, key string) bool

RangesNatively forwards the inner answer, since ByteCounter.ReadAt reads whole wherever the inner backend does. Implements backend.RangeHinter.

func (*ByteCounter) Read added in v0.49.0

func (b *ByteCounter) Read(ctx context.Context, key string) ([]byte, error)

Read implements backend.Backend.

func (*ByteCounter) ReadAt added in v0.49.0

func (b *ByteCounter) ReadAt(ctx context.Context, key string, off, n int64) ([]byte, error)

ReadAt implements backend.ReaderAt.

func (*ByteCounter) ReadView added in v0.49.0

func (b *ByteCounter) ReadView(ctx context.Context, key string) ([]byte, error)

ReadView implements backend.Viewer.

func (*ByteCounter) Reads added in v0.49.0

func (b *ByteCounter) Reads() int64

Reads returns the reads made since the last ByteCounter.Reset.

func (*ByteCounter) Report added in v0.49.0

func (b *ByteCounter) Report() string

Report renders the per-key byte totals, one sorted line per key, so a failure says which object was read rather than only how much.

func (*ByteCounter) Reset added in v0.49.0

func (b *ByteCounter) Reset()

Reset zeroes every count.

type Capacity added in v0.40.0

type Capacity struct {
	backend.Backend
	// contains filtered or unexported fields
}

Capacity wraps a backend with a settable capacity report, so a test can put an engine on a full disk or an exhausted inode table without needing a real one. The two axes are set independently: a filesystem with terabytes free can still fail every create, and a test must be able to say so.

Like github.com/oteldb/storage/backend/faultbackend it forwards no other optional capability — each has a mandatory fallback, so a wrapped backend runs the same code, only slower.

func WithCapacity added in v0.40.0

func WithCapacity(b backend.Backend, freeBytes, freeInodes int64) *Capacity

WithCapacity wraps b reporting freeBytes bytes and freeInodes inodes available (Unknown for an axis the backend cannot report).

func (*Capacity) FreeInodes added in v0.40.0

func (c *Capacity) FreeInodes(context.Context) (int64, error)

FreeInodes implements backend.InodeReporter.

func (*Capacity) FreeSpace added in v0.40.0

func (c *Capacity) FreeSpace(context.Context) (int64, error)

FreeSpace implements backend.SpaceReporter.

func (*Capacity) SetFreeBytes added in v0.40.0

func (c *Capacity) SetFreeBytes(n int64)

SetFreeBytes changes the reported free bytes — the disk filling up, or being emptied.

func (*Capacity) SetFreeInodes added in v0.40.0

func (c *Capacity) SetFreeInodes(n int64)

SetFreeInodes changes the reported free inodes.

type Case added in v0.49.0

type Case struct {
	Name string
	Open func(tb testing.TB) backend.Backend
}

Case names a backend factory in a test or benchmark table.

func Cached added in v0.49.0

func Cached(c Case, budget int64) Case

Cached is c behind a backend.Cached read cache of budget bytes, named "cached-" + c.Name.

func Dir added in v0.49.0

func Dir[B backend.Backend](name string, open func(dir string) (B, error)) Case

Dir is a case that opens a backend over a fresh tb.TempDir, failing tb when open does.

func Matrix added in v0.49.0

func Matrix(file, s3 Case) []Case

Matrix is every read path a backend offers: memory, file, file behind a 1 MiB read cache, s3, and WholeObject. This package cannot import the file or s3 backends, so the caller supplies them.

func Memory added in v0.49.0

func Memory() Case

Memory is the backend.Memory case.

func WholeObject added in v0.49.0

func WholeObject() Case

WholeObject is memory behind WithoutCapabilities: every read is a whole-object Read.

type Counting added in v0.49.0

type Counting struct {
	backend.Backend
	// contains filtered or unexported fields
}

Counting counts reads per key and can fail the n-th write. It embeds the Backend interface, so it forwards no optional capability: every read, a view or a size probe included, funnels through Read and is counted.

func NewCounting added in v0.49.0

func NewCounting(b backend.Backend) *Counting

NewCounting wraps b.

func (*Counting) FailWriteAt added in v0.49.0

func (c *Counting) FailWriteAt(n int)

FailWriteAt makes the n-th write from now on fail with ErrInjected; n ≤ 0 disables injection.

func (*Counting) Read added in v0.49.0

func (c *Counting) Read(ctx context.Context, key string) ([]byte, error)

Read implements backend.Backend.

func (*Counting) Reads added in v0.49.0

func (c *Counting) Reads() map[string]int

Reads returns a snapshot of the per-key read counts.

func (*Counting) Write added in v0.49.0

func (c *Counting) Write(ctx context.Context, key string, data []byte) error

Write implements backend.Backend.

func (*Counting) Writes added in v0.49.0

func (c *Counting) Writes() int

Writes returns how many writes have happened since the last Counting.FailWriteAt.

type Deferred added in v0.47.0

type Deferred struct {
	backend.Backend
	// contains filtered or unexported fields
}

Deferred wraps a backend with a backend.DeferredSyncer that remembers which deferred writes and deletes no SyncPrefix has covered yet, so a test can assert that nothing durable names a prefix while it still has some. It also implements backend.ObjectCreator, so a streaming writer takes its streaming path over a backend that buffers — while StreamsWrites still answers for that backend, which does not.

func WithDeferred added in v0.47.0

func WithDeferred(b backend.Backend) *Deferred

WithDeferred wraps b.

func (*Deferred) CreateObject added in v0.47.0

func (d *Deferred) CreateObject(ctx context.Context, key string) (backend.ObjectWriter, error)

CreateObject implements backend.ObjectCreator.

func (*Deferred) CreateObjectDeferred added in v0.47.0

func (d *Deferred) CreateObjectDeferred(ctx context.Context, key string) (backend.ObjectWriter, error)

CreateObjectDeferred implements backend.DeferredSyncer.

func (*Deferred) Delete added in v0.47.0

func (d *Deferred) Delete(ctx context.Context, key string) error

Delete implements backend.Backend.

func (*Deferred) DeleteDeferred added in v0.47.0

func (d *Deferred) DeleteDeferred(ctx context.Context, key string) error

DeleteDeferred implements backend.DeferredSyncer.

func (*Deferred) Deletes added in v0.47.0

func (d *Deferred) Deletes() []string

Deletes returns every delete in the order it happened, a deferred one marked with a "~" prefix.

func (*Deferred) Pending added in v0.47.0

func (d *Deferred) Pending(prefix string) []string

Pending returns, sorted, the keys under prefix whose deferred operation is not yet synced.

func (*Deferred) StreamsWrites added in v0.48.0

func (d *Deferred) StreamsWrites() bool

StreamsWrites answers for the wrapped backend. Implements backend.ObjectCreator.

func (*Deferred) SyncPrefix added in v0.47.0

func (d *Deferred) SyncPrefix(_ context.Context, prefix string) error

SyncPrefix implements backend.DeferredSyncer.

func (*Deferred) WriteDeferred added in v0.47.0

func (d *Deferred) WriteDeferred(ctx context.Context, key string, data []byte) error

WriteDeferred implements backend.DeferredSyncer.

type SizedByteCounter added in v0.49.0

type SizedByteCounter struct{ *ByteCounter }

SizedByteCounter is a ByteCounter that also forwards backend.Sizer (through backend.SizeOf), so a ranged open learns an object's length without reading it whole.

func NewSizedByteCounter added in v0.49.0

func NewSizedByteCounter(b backend.Backend) SizedByteCounter

NewSizedByteCounter wraps b.

func (SizedByteCounter) Size added in v0.49.0

func (b SizedByteCounter) Size(ctx context.Context, key string) (int64, error)

Size implements backend.Sizer.

type StreamingMemory added in v0.49.0

type StreamingMemory struct {
	backend.Backend
	// contains filtered or unexported fields
}

StreamingMemory is backend.Memory plus the incremental-write backend.ObjectCreator, standing in for the file backend so the streamed write path runs without a disk. Its writer buffers and commits with one Write. It embeds the Backend interface, so memory's other capabilities (backend.Viewer, backend.Sizer, …) are hidden, except ranged reads: memory serves those natively, and a merge chooses between a windowed and a whole read by backend.RangesNatively.

func NewStreamingMemory added in v0.49.0

func NewStreamingMemory() *StreamingMemory

NewStreamingMemory returns an empty StreamingMemory.

func (*StreamingMemory) CreateObject added in v0.49.0

func (b *StreamingMemory) CreateObject(_ context.Context, key string) (backend.ObjectWriter, error)

CreateObject implements backend.ObjectCreator.

func (*StreamingMemory) Creates added in v0.49.0

func (b *StreamingMemory) Creates() int64

Creates returns how many objects CreateObject has opened.

func (*StreamingMemory) ReadAt added in v0.49.0

func (b *StreamingMemory) ReadAt(ctx context.Context, key string, off, n int64) ([]byte, error)

ReadAt implements backend.ReaderAt.

func (*StreamingMemory) StreamsWrites added in v0.49.0

func (*StreamingMemory) StreamsWrites() bool

StreamsWrites implements backend.ObjectCreator.

Jump to

Keyboard shortcuts

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