testkit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package testkit provides testing utilities including fake clocks, in-memory GCS clients, and controllable backends.

Index

Constants

View Source
const RaceEnabled = false

RaceEnabled is true when the package was compiled with the go race detector enabled.

Not sure of any better way to do it as of writing this.

Variables

This section is empty.

Functions

func NewAcceleratedClock

func NewAcceleratedClock(multiplier int) clockwork.Clock

NewAcceleratedClock creates a clock that runs faster than real time by the given multiplier.

func NewGCSClient

func NewGCSClient(ctx context.Context, t testing.TB, logging bool) *storage.Client

NewGCSClient creates a GCS storage client backed by an in-memory fake server for testing.

func NewLogger

func NewLogger(tb testing.TB, opts *slog.HandlerOptions) *slog.Logger

NewLogger creates a new logger that writes to the testing.TB.

func NewSelfAdvanceClock

func NewSelfAdvanceClock(t *testing.T) clockwork.Clock

NewSelfAdvanceClock creates a fake clock that automatically advances when sleepers are waiting.

Types

type StallBackend

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

StallBackend is a backend where writes can be paused and resumed.

When a write is stalled, it returns immediately with an error. It will complete asynchronously only when released.

func NewStallBackend

func NewStallBackend(inner backend.Backend) *StallBackend

NewStallBackend wraps a backend so that writes can be paused, stalled, and released.

func (*StallBackend) Delete

func (b *StallBackend) Delete(ctx context.Context, path string) error

Delete removes an object at the given path, stalling if stalling is enabled.

func (*StallBackend) DeleteIf

func (b *StallBackend) DeleteIf(
	ctx context.Context,
	path string,
	expected backend.Version,
) error

DeleteIf removes an object conditionally, stalling if stalling is enabled.

func (*StallBackend) ReleaseStalled

func (b *StallBackend) ReleaseStalled()

ReleaseStalled allows all previously stalled write operations to complete.

func (*StallBackend) SetTagsIf

func (b *StallBackend) SetTagsIf(
	ctx context.Context,
	path string,
	expected backend.Version,
	t backend.Tags,
) (backend.Metadata, error)

SetTagsIf sets tags on a path conditionally, stalling if stalling is enabled.

func (*StallBackend) StallWrites

func (b *StallBackend) StallWrites()

StallWrites causes all subsequent write operations to be held until released.

func (*StallBackend) StopStalling

func (b *StallBackend) StopStalling()

StopStalling allows new write operations to proceed normally without stalling.

func (*StallBackend) WaitForStalled

func (b *StallBackend) WaitForStalled()

WaitForStalled blocks until all stalled write operations have been queued.

func (*StallBackend) Write

func (b *StallBackend) Write(
	ctx context.Context,
	path string,
	value []byte,
	t backend.Tags,
) (backend.Metadata, error)

func (*StallBackend) WriteIf

func (b *StallBackend) WriteIf(
	ctx context.Context,
	path string,
	value []byte,
	expected backend.Version,
	t backend.Tags,
) (backend.Metadata, error)

WriteIf writes a value conditionally, stalling if stalling is enabled.

func (*StallBackend) WriteIfNotExists

func (b *StallBackend) WriteIfNotExists(
	ctx context.Context,
	path string,
	value []byte,
	t backend.Tags,
) (backend.Metadata, error)

WriteIfNotExists writes a value only if the path does not exist, stalling if stalling is enabled.

Directories

Path Synopsis
Package bench provides utilities for collecting and analyzing performance measurements.
Package bench provides utilities for collecting and analyzing performance measurements.

Jump to

Keyboard shortcuts

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