backendtest

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

This section is empty.

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 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.

Types

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 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.

Jump to

Keyboard shortcuts

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