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 ¶
- type BigSegmentStoreTestSuite
- type PersistentDataStoreTestSuite
- func (s *PersistentDataStoreTestSuite) ConcurrentModificationHook(setHookFn func(store ssys.PersistentDataStore, hook func())) *PersistentDataStoreTestSuite
- func (s *PersistentDataStoreTestSuite) ErrorStoreFactory(errorStoreFactory ssys.ComponentConfigurer[ssys.PersistentDataStore], ...) *PersistentDataStoreTestSuite
- func (s *PersistentDataStoreTestSuite) Run(t *testing.T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BigSegmentStoreTestSuite ¶
type BigSegmentStoreTestSuite struct {
// contains filtered or unexported fields
}
BigSegmentStoreTestSuite provides a configurable test suite for all implementations of BigSegmentStore.
func NewBigSegmentStoreTestSuite ¶
func NewBigSegmentStoreTestSuite( storeFactoryFn func(prefix string) subsystems.ComponentConfigurer[subsystems.BigSegmentStore], clearDataFn func(prefix string) error, setMetadataFn func(prefix string, metadata subsystems.BigSegmentStoreMetadata) error, setSegmentsFn func(prefix string, userHashKey string, included []string, excluded []string) error, ) *BigSegmentStoreTestSuite
NewBigSegmentStoreTestSuite creates an BigSegmentStoreTestSuite for testing some implementation of BigSegmentStore.
The storeFactoryFn parameter is a function that takes a prefix string and returns a configured factory for this data store type (for instance, ldredis.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.
The setMetadataFn and setSegmentsFn parameters are functions for populating the database. The string slices passed to setSegmentsFn are lists of segment references in the same format used by BigSegmentMembership, and should be used as-is by the store.
func (*BigSegmentStoreTestSuite) Run ¶
func (s *BigSegmentStoreTestSuite) Run(t *testing.T)
Run runs the configured test suite.
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) ssys.ComponentConfigurer[ssys.PersistentDataStore], 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 ssys.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 ssys.ComponentConfigurer[ssys.PersistentDataStore], 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 ¶
func (s *PersistentDataStoreTestSuite) Run(t *testing.T)
Run runs the configured test suite.