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 ¶
- Variables
- func AddItem(ctx context.Context, t *testing.T, uut backend.Backend, key []byte, ...) (backend.Item, backend.Lease)
- func MakePrefix() func(k string) []byte
- func RequireItems(t *testing.T, expected, actual []backend.Item)
- func RunAtomicWriteComplianceSuite(t *testing.T, newBackend AtomicWriteConstructor)
- func RunBackendComplianceSuite(t *testing.T, newBackend Constructor)
- func RunBackendComplianceSuiteWithAtomicWriteShim(t *testing.T, newBackend AtomicWriteConstructor)
- type AtomicWriteConstructor
- type AtomicWriteShim
- func (a AtomicWriteShim) CompareAndSwap(ctx context.Context, expected backend.Item, replaceWith backend.Item) (*backend.Lease, error)
- func (a AtomicWriteShim) ConditionalDelete(ctx context.Context, key []byte, revision string) error
- func (a AtomicWriteShim) ConditionalUpdate(ctx context.Context, i backend.Item) (*backend.Lease, error)
- func (a AtomicWriteShim) Create(ctx context.Context, i backend.Item) (*backend.Lease, error)
- func (a AtomicWriteShim) Delete(ctx context.Context, key []byte) error
- func (a AtomicWriteShim) Put(ctx context.Context, i backend.Item) (*backend.Lease, error)
- func (a AtomicWriteShim) Update(ctx context.Context, i backend.Item) (*backend.Lease, error)
- type BlockingFakeClock
- type ConstructionOption
- type ConstructionOptions
- type Constructor
Constants ¶
This section is empty.
Variables ¶
var ( ErrMirrorNotSupported = errors.New("mirror mode not supported") ErrConcurrentAccessNotSupported = errors.New("concurrent access not supported") )
Functions ¶
func MakePrefix ¶
MakePrefix returns function that appends unique prefix to any key, used to make test suite concurrent-run proof
func RequireItems ¶
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 ¶
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) Delete ¶
func (a AtomicWriteShim) Delete(ctx context.Context, key []byte) error
Delete deletes item by key, returns NotFound error if item does not exist
type BlockingFakeClock ¶
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 ¶
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.