Documentation ¶
Overview ¶
Package storetest contains the standard test suite for persistent data store implementations.
This is in its own subpackage because it references the main go-server-sdk.v5 package, and the main package needs to use other unrelated APIs in testhelpers.
Index ¶
- type PersistentDataStoreTestSuite
- func (s *PersistentDataStoreTestSuite) AlwaysRun(alwaysRun bool) *PersistentDataStoreTestSuite
- func (s *PersistentDataStoreTestSuite) ConcurrentModificationHook(setHookFn func(store intf.PersistentDataStore, hook func())) *PersistentDataStoreTestSuite
- func (s *PersistentDataStoreTestSuite) ErrorStoreFactory(errorStoreFactory intf.PersistentDataStoreFactory, ...) *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 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) AlwaysRun ¶
func (s *PersistentDataStoreTestSuite) AlwaysRun(alwaysRun bool) *PersistentDataStoreTestSuite
AlwaysRun specifies whether this test suite should always be run even if the environment variable LD_SKIP_DATABASE_TESTS is set.
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 ¶
func (s *PersistentDataStoreTestSuite) Run(t *testing.T)
Run runs the configured test suite.