storetest

package
v5.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package storetest contains the standard test suite for persistent data store implementations.

If you are writing your own database integration, use this test suite to ensure that it is being fully tested in the same way that all of the built-in ones are tested.

Due to its dependencies, this package can only be used when building with module support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PersistentDataStoreTestSuite

type PersistentDataStoreTestSuite struct {
	// contains filtered or unexported fields
}

PersistentDataStoreTestSuite provides a configurable test suite for all implementations of PersistentDataStore.

In order to be testable with this tool, a data store implementation must have the following characteristics:

1. It has some notion of a "prefix" string that can be used to distinguish between different SDK instances using the same underlying database.

2. Two instances of the same data store type with the same configuration, and the same prefix, should be able to see each other's data.

func NewPersistentDataStoreTestSuite

func NewPersistentDataStoreTestSuite(
	storeFactoryFn func(prefix string) intf.PersistentDataStoreFactory,
	clearDataFn func(prefix string) error,
) *PersistentDataStoreTestSuite

NewPersistentDataStoreTestSuite creates a PersistentDataStoreTestSuite for testing some implementation of PersistentDataStore.

The storeFactoryFn parameter is a function that takes a prefix string and returns a configured factory for this data store type (for instance, ldconsul.DataStore().Prefix(prefix)). If the prefix string is "", it should use the default prefix defined by the data store implementation. The factory must include any necessary configuration that may be appropriate for the test environment (for instance, pointing it to a database instance that has been set up for the tests).

The clearDataFn parameter is a function that takes a prefix string and deletes any existing data that may exist in the database corresponding to that prefix.

func (*PersistentDataStoreTestSuite) ConcurrentModificationHook

func (s *PersistentDataStoreTestSuite) ConcurrentModificationHook(
	setHookFn func(store intf.PersistentDataStore, hook func()),
) *PersistentDataStoreTestSuite

ConcurrentModificationHook enables tests of concurrent modification behavior, for store implementations that support testing this.

The hook parameter is a function which, when called with a store instance and another function as parameters, will modify the store instance so that it will call the latter function synchronously during each Upsert operation - after the old value has been read, but before the new one has been written.

func (*PersistentDataStoreTestSuite) ErrorStoreFactory

func (s *PersistentDataStoreTestSuite) ErrorStoreFactory(
	errorStoreFactory intf.PersistentDataStoreFactory,
	errorValidator func(assert.TestingT, error),
) *PersistentDataStoreTestSuite

ErrorStoreFactory enables a test of error handling. The provided errorStoreFactory is expected to produce a data store instance whose operations should all fail and return an error. The errorValidator function, if any, will be called to verify that it is the expected error.

func (*PersistentDataStoreTestSuite) Run

Run runs the configured test suite.

Jump to

Keyboard shortcuts

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