test

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package test contains a backend acceptance test suite that is backend implementation independent each backend will use the suite to test itself

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMirrorNotSupported           = errors.New("mirror mode not supported")
	ErrConcurrentAccessNotSupported = errors.New("concurrent access not supported")
)

Functions

func AddItem

func AddItem(ctx context.Context, t *testing.T, uut backend.Backend, key []byte, value string, expires time.Time) (backend.Item, backend.Lease)

func MakePrefix

func MakePrefix() func(k string) []byte

MakePrefix returns function that appends unique prefix to any key, used to make test suite concurrent-run proof

func RequireItems

func RequireItems(t *testing.T, expected, actual []backend.Item)

RequireItems asserts that the supplied `actual` items collection matches the `expected` collection, in size, ordering and the key/value pairs of each entry.

func RunAtomicWriteComplianceSuite

func RunAtomicWriteComplianceSuite(t *testing.T, newBackend AtomicWriteConstructor)

func RunBackendComplianceSuite

func RunBackendComplianceSuite(t *testing.T, newBackend Constructor)

RunBackendComplianceSuite runs the entire backend compliance suite, creating a collection of named subtests under the context provided by `t`.

As each test requires a new backend instance it will invoke the supplied `newBackend` function, which callers will use inject instances of the backend under test.

func RunBackendComplianceSuiteWithAtomicWriteShim

func RunBackendComplianceSuiteWithAtomicWriteShim(t *testing.T, newBackend AtomicWriteConstructor)

RunBackendComplianceSuiteWithAtomicWriteShim runs the old backend compliance suite against the provided backend with a shim that converts all calls to single-write methods (all write methods but DeleteRange) into calls to AtomicWrite. This is done to ensure that the relationship between the conditional actions of AtomicWrite and the single-write methods is well defined, and to improve overall coverage of AtomicWrite implementations via reuse.

Types

type AtomicWriteConstructor

type AtomicWriteConstructor func(options ...ConstructionOption) (backend.AtomicWriterBackend, clockwork.FakeClock, error)

AtomicWriteConstructor is equivalent to Constructor, except that it includes the new AtomicWrite method. This type will be deprecated once all backends implement AtomicWrite.

type AtomicWriteShim

type AtomicWriteShim struct {
	backend.AtomicWriterBackend
	// contains filtered or unexported fields
}

atomciWriteShim reimplements all single-write backend methods as calls to AtomicWrite.

func (AtomicWriteShim) CompareAndSwap

func (a AtomicWriteShim) CompareAndSwap(ctx context.Context, expected backend.Item, replaceWith backend.Item) (*backend.Lease, error)

CompareAndSwap compares item with existing item and replaces is with replaceWith item

func (AtomicWriteShim) ConditionalDelete

func (a AtomicWriteShim) ConditionalDelete(ctx context.Context, key []byte, revision string) error

ConditionalDelete deletes the item by key if the revision matches the stored revision.

func (AtomicWriteShim) ConditionalUpdate

func (a AtomicWriteShim) ConditionalUpdate(ctx context.Context, i backend.Item) (*backend.Lease, error)

ConditionalUpdate updates the value in the backend if the revision of the backend.Item matches the stored revision.

func (AtomicWriteShim) Create

Create creates item if it does not exist

func (AtomicWriteShim) Delete

func (a AtomicWriteShim) Delete(ctx context.Context, key []byte) error

Delete deletes item by key, returns NotFound error if item does not exist

func (AtomicWriteShim) Put

Put puts value into backend (creates if it does not exists, updates it otherwise)

func (AtomicWriteShim) Update

Update updates value in the backend

type BlockingFakeClock

type BlockingFakeClock struct {
	clockwork.Clock
}

BlockingFakeClock simulates a fake clock by sleeping instead of advancing an actual fake clock. This is required for backend clients which cannot time travel via a fake clock.

func (BlockingFakeClock) Advance

func (r BlockingFakeClock) Advance(d time.Duration)

func (BlockingFakeClock) BlockUntil

func (r BlockingFakeClock) BlockUntil(int)

type ConstructionOption

type ConstructionOption func(*ConstructionOptions) error

ConstructionOption describes a named-parameter setting function for configuring a ConstructionOptions instance

func WithConcurrentBackend

func WithConcurrentBackend(target backend.Backend) ConstructionOption

WithConcurrentBackend asks the constructor to create a

func WithMirrorMode

func WithMirrorMode(mirror bool) ConstructionOption

WithMirrorMode asks the constructor to create a Backend in "mirror mode". Not all backends will support this.

type ConstructionOptions

type ConstructionOptions struct {
	MirrorMode bool

	// ConcurrentBackend indicates that the Backend Constructor function should not
	// create an entirely independent data store, but instead should create a
	// new interface to the same underlying data store as `ConcurrentBackend`.
	ConcurrentBackend backend.Backend
}

func ApplyOptions

func ApplyOptions(options []ConstructionOption) (*ConstructionOptions, error)

ApplyOptions constructs a new `ConstructionOptions` value from a sensible default and then applies the supplied options to it.

func (*ConstructionOptions) Apply

func (opts *ConstructionOptions) Apply(options []ConstructionOption) error

Apply applies a collection of option-setting functions to the receiver, modifying it in-place.

type Constructor

type Constructor func(options ...ConstructionOption) (backend.Backend, clockwork.FakeClock, error)

Constructor describes a function for constructing new instances of a backend, with various options as required by a given test. Note that it's the caller's responsibility to close it when the test is finished.

Jump to

Keyboard shortcuts

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