Documentation ¶
Overview ¶
Package sharedtest contains types and functions used by SDK unit tests in multiple packages.
Since it is inside internal/, none of this code can be seen by application code and it can be freely changed without breaking any public APIs. Test helpers that we want to be available to application code should be in testhelpers/ instead.
It is important that no non-test code ever imports this package, so that it will not be compiled into applications as a transitive dependency.
Note that this package is not allowed to reference the "internal" package, because the tests in that package use sharedtest helpers so it would be a circular reference.
Index ¶
- Variables
- func AssertNotNil(i interface{})
- func AssertValuesJSONEqual(t *testing.T, expected interface{}, actual interface{})
- func DataSetToMap(allData []ldstoretypes.Collection) map[ldstoretypes.DataKind]map[string]ldstoretypes.ItemDescriptor
- func DataSourceThatIsAlwaysInitialized() interfaces.DataSourceFactory
- func DataSourceThatNeverInitializes() interfaces.DataSourceFactory
- func ExpectBigSegmentStoreStatus(t *testing.T, statusCh <-chan interfaces.BigSegmentStoreStatus, ...)
- func ExpectFlagChangeEvents(t *testing.T, ch <-chan interfaces.FlagChangeEvent, keys ...string)
- func ExpectNoMoreFlagChangeEvents(t *testing.T, ch <-chan interfaces.FlagChangeEvent)
- func ExpectNoMoreFlagValueChangeEvents(t *testing.T, ch <-chan interfaces.FlagValueChangeEvent)
- func FlagDescriptor(f ldmodel.FeatureFlag) ldstoretypes.ItemDescriptor
- func MakeMockDataSet(items ...MockDataItem) []ldstoretypes.Collection
- func MakeSerializedMockDataSet(items ...MockDataItem) []ldstoretypes.SerializedCollection
- func NewSimpleTestContext(sdkKey string) interfaces.ClientContext
- func NewTestContext(sdkKey string, http interfaces.HTTPConfiguration, ...) interfaces.ClientContext
- func NewTestLoggers() ldlog.Loggers
- func NormalizeDataSet(in []ldstoretypes.Collection) []ldstoretypes.Collection
- func SegmentDescriptor(s ldmodel.Segment) ldstoretypes.ItemDescriptor
- func TestHTTP() interfaces.HTTPConfigurationFactory
- func TestHTTPConfig() interfaces.HTTPConfiguration
- func TestHTTPConfigWithHeaders(headers http.Header) interfaces.HTTPConfiguration
- func TestLogging() interfaces.LoggingConfigurationFactory
- func TestLoggingConfig() interfaces.LoggingConfiguration
- func TestLoggingConfigWithLoggers(loggers ldlog.Loggers) interfaces.LoggingConfiguration
- func WithTempFileContaining(data []byte, action func(filename string))
- type CapturingDataStore
- func (d *CapturingDataStore) Close() error
- func (d *CapturingDataStore) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDescriptor, error)
- func (d *CapturingDataStore) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error)
- func (d *CapturingDataStore) Init(allData []ldstoretypes.Collection) error
- func (d *CapturingDataStore) IsInitialized() bool
- func (d *CapturingDataStore) IsStatusMonitoringEnabled() bool
- func (d *CapturingDataStore) SetFakeError(fakeError error)
- func (d *CapturingDataStore) SetStatusMonitoringEnabled(statusMonitoringEnabled bool)
- func (d *CapturingDataStore) Upsert(kind ldstoretypes.DataKind, key string, newItem ldstoretypes.ItemDescriptor) (bool, error)
- func (d *CapturingDataStore) WaitForDelete(t *testing.T, kind ldstoretypes.DataKind, key string, version int, ...)
- func (d *CapturingDataStore) WaitForInit(t *testing.T, data *ldservices.ServerSDKData, timeout time.Duration)
- func (d *CapturingDataStore) WaitForNextInit(t *testing.T, timeout time.Duration) []ldstoretypes.Collection
- func (d *CapturingDataStore) WaitForNextUpsert(t *testing.T, timeout time.Duration) UpsertParams
- func (d *CapturingDataStore) WaitForUpsert(t *testing.T, kind ldstoretypes.DataKind, key string, version int, ...) UpsertParams
- type CapturingEventProcessor
- func (c *CapturingEventProcessor) Close() error
- func (c *CapturingEventProcessor) Flush()
- func (c *CapturingEventProcessor) RecordAliasEvent(e ldevents.AliasEvent)
- func (c *CapturingEventProcessor) RecordCustomEvent(e ldevents.CustomEvent)
- func (c *CapturingEventProcessor) RecordFeatureRequestEvent(e ldevents.FeatureRequestEvent)
- func (c *CapturingEventProcessor) RecordIdentifyEvent(e ldevents.IdentifyEvent)
- type DataSetBuilder
- type DataSourceFactoryThatExposesUpdater
- type DataSourceFactoryWithData
- type DataStoreFactoryThatExposesUpdater
- type MockBigSegmentStore
- func (m *MockBigSegmentStore) Close() error
- func (m *MockBigSegmentStore) GetMetadata() (interfaces.BigSegmentStoreMetadata, error)
- func (m *MockBigSegmentStore) GetUserMembership(userHash string) (interfaces.BigSegmentMembership, error)
- func (m *MockBigSegmentStore) TestGetMembershipQueries() []string
- func (m *MockBigSegmentStore) TestGetMetadataQueriesCh() <-chan struct{}
- func (m *MockBigSegmentStore) TestSetMembership(userHash string, membership interfaces.BigSegmentMembership)
- func (m *MockBigSegmentStore) TestSetMembershipError(err error)
- func (m *MockBigSegmentStore) TestSetMetadataState(md interfaces.BigSegmentStoreMetadata, err error)
- func (m *MockBigSegmentStore) TestSetMetadataToCurrentTime()
- type MockDataItem
- type MockDataSourceUpdates
- func (d *MockDataSourceUpdates) GetDataStoreStatusProvider() interfaces.DataStoreStatusProvider
- func (d *MockDataSourceUpdates) Init(allData []ldstoretypes.Collection) bool
- func (d *MockDataSourceUpdates) RequireStatus(t *testing.T) interfaces.DataSourceStatus
- func (d *MockDataSourceUpdates) RequireStatusOf(t *testing.T, newState interfaces.DataSourceState) interfaces.DataSourceStatus
- func (d *MockDataSourceUpdates) UpdateStatus(newState interfaces.DataSourceState, newError interfaces.DataSourceErrorInfo)
- func (d *MockDataSourceUpdates) UpdateStoreStatus(newStatus interfaces.DataStoreStatus)
- func (d *MockDataSourceUpdates) Upsert(kind ldstoretypes.DataKind, key string, newItem ldstoretypes.ItemDescriptor) bool
- type MockDatabaseInstance
- type MockPersistentDataStore
- func (m *MockPersistentDataStore) Close() error
- func (m *MockPersistentDataStore) EnableInstrumentedQueries(queryDelay time.Duration) <-chan struct{}
- func (m *MockPersistentDataStore) ForceGet(kind ldstoretypes.DataKind, key string) ldstoretypes.SerializedItemDescriptor
- func (m *MockPersistentDataStore) ForceRemove(kind ldstoretypes.DataKind, key string)
- func (m *MockPersistentDataStore) ForceSet(kind ldstoretypes.DataKind, key string, ...)
- func (m *MockPersistentDataStore) ForceSetInited(inited bool)
- func (m *MockPersistentDataStore) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.SerializedItemDescriptor, error)
- func (m *MockPersistentDataStore) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedSerializedItemDescriptor, error)
- func (m *MockPersistentDataStore) Init(allData []ldstoretypes.SerializedCollection) error
- func (m *MockPersistentDataStore) IsInitialized() bool
- func (m *MockPersistentDataStore) IsStoreAvailable() bool
- func (m *MockPersistentDataStore) SetAvailable(available bool)
- func (m *MockPersistentDataStore) SetFakeError(fakeError error)
- func (m *MockPersistentDataStore) SetPersistOnlyAsString(value bool)
- func (m *MockPersistentDataStore) SetTestTxHook(hook func())
- func (m *MockPersistentDataStore) Upsert(kind ldstoretypes.DataKind, key string, ...) (bool, error)
- type SingleBigSegmentStoreFactory
- type SingleDataStoreFactory
- type SingleEventProcessorFactory
- type SinglePersistentDataStoreFactory
- type UpsertParams
Constants ¶
This section is empty.
Variables ¶
var MockData = mockDataKind{/* contains filtered or unexported fields */}
MockData is an instance of ld.StoreDataKind corresponding to MockDataItem.
var MockOtherData = mockDataKind{/* contains filtered or unexported fields */}
MockOtherData is an instance of ld.StoreDataKind corresponding to another flavor of MockDataItem.
Functions ¶
func AssertNotNil ¶
func AssertNotNil(i interface{})
AssertNotNil forces a panic if the specified value is nil (either a nil interface value, or a nil pointer).
func AssertValuesJSONEqual ¶ added in v5.0.1
AssertValuesJSONEqual serializes both values to JSON and calls assert.JSONEq.
func DataSetToMap ¶
func DataSetToMap( allData []ldstoretypes.Collection, ) map[ldstoretypes.DataKind]map[string]ldstoretypes.ItemDescriptor
DataSetToMap converts the data format for Init into a map of maps.
func DataSourceThatIsAlwaysInitialized ¶
func DataSourceThatIsAlwaysInitialized() interfaces.DataSourceFactory
DataSourceThatIsAlwaysInitialized returns a test DataSourceFactory that produces a data source that immediately reports success on startup, although it does not provide any data.
func DataSourceThatNeverInitializes ¶
func DataSourceThatNeverInitializes() interfaces.DataSourceFactory
DataSourceThatNeverInitializes returns a test DataSourceFactory that produces a data source that immediately starts up in a failed state and does not provide any data.
func ExpectBigSegmentStoreStatus ¶ added in v5.5.0
func ExpectBigSegmentStoreStatus( t *testing.T, statusCh <-chan interfaces.BigSegmentStoreStatus, statusGetter func() interfaces.BigSegmentStoreStatus, timeout time.Duration, expectedStatus interfaces.BigSegmentStoreStatus, )
ExpectBigSegmentStoreStatus waits for a status value to appear in a channel and also verifies that it matches the status currently being reported by the status provider.
func ExpectFlagChangeEvents ¶
func ExpectFlagChangeEvents(t *testing.T, ch <-chan interfaces.FlagChangeEvent, keys ...string)
ExpectFlagChangeEvents asserts that a channel receives flag change events for the specified keys (in any order) and then does not receive any more events for the next 100ms.
func ExpectNoMoreFlagChangeEvents ¶
func ExpectNoMoreFlagChangeEvents(t *testing.T, ch <-chan interfaces.FlagChangeEvent)
ExpectNoMoreFlagChangeEvents asserts that a channel does not receive any flag change events for the next 100ms.
func ExpectNoMoreFlagValueChangeEvents ¶
func ExpectNoMoreFlagValueChangeEvents(t *testing.T, ch <-chan interfaces.FlagValueChangeEvent)
ExpectNoMoreFlagValueChangeEvents asserts that a channel does not receive any flag value change events for the next 100ms.
func FlagDescriptor ¶
func FlagDescriptor(f ldmodel.FeatureFlag) ldstoretypes.ItemDescriptor
FlagDescriptor is a shortcut for creating a StoreItemDescriptor from a flag.
func MakeMockDataSet ¶
func MakeMockDataSet(items ...MockDataItem) []ldstoretypes.Collection
MakeMockDataSet constructs a data set to be passed to a data store's Init method.
func MakeSerializedMockDataSet ¶
func MakeSerializedMockDataSet(items ...MockDataItem) []ldstoretypes.SerializedCollection
MakeSerializedMockDataSet constructs a data set to be passed to a persistent data store's Init method.
func NewSimpleTestContext ¶
func NewSimpleTestContext(sdkKey string) interfaces.ClientContext
NewSimpleTestContext returns a basic implementation of interfaces.ClientContext for use in test code.
func NewTestContext ¶
func NewTestContext( sdkKey string, http interfaces.HTTPConfiguration, logging interfaces.LoggingConfiguration, ) interfaces.ClientContext
NewTestContext returns a basic implementation of interfaces.ClientContext for use in test code. We can't use internal.NewClientContextImpl for this because of circular references.
func NewTestLoggers ¶
NewTestLoggers returns a standardized logger instance used by unit tests. If you want to temporarily enable log output for tests, change testLogLevel to for instance ldlog.Debug. Note that "go test" normally suppresses output anyway unless a test fails.
func NormalizeDataSet ¶ added in v5.1.0
func NormalizeDataSet(in []ldstoretypes.Collection) []ldstoretypes.Collection
NormalizeDataSet sorts the data set by kind and key for test determinacy.
func SegmentDescriptor ¶
func SegmentDescriptor(s ldmodel.Segment) ldstoretypes.ItemDescriptor
SegmentDescriptor is a shortcut for creating a StoreItemDescriptor from a segment.
func TestHTTP ¶
func TestHTTP() interfaces.HTTPConfigurationFactory
TestHTTP returns a basic HTTPConfigurationFactory for test code.
func TestHTTPConfig ¶
func TestHTTPConfig() interfaces.HTTPConfiguration
TestHTTPConfig returns a basic HTTPConfiguration for test code.
func TestHTTPConfigWithHeaders ¶
func TestHTTPConfigWithHeaders(headers http.Header) interfaces.HTTPConfiguration
TestHTTPConfigWithHeaders returns a basic HTTPConfiguration with the specified HTTP headers.
func TestLogging ¶
func TestLogging() interfaces.LoggingConfigurationFactory
TestLogging returns a LoggingConfigurationFactory corresponding to NewTestLoggers().
func TestLoggingConfig ¶
func TestLoggingConfig() interfaces.LoggingConfiguration
TestLoggingConfig returns a LoggingConfiguration corresponding to NewTestLoggers().
func TestLoggingConfigWithLoggers ¶
func TestLoggingConfigWithLoggers(loggers ldlog.Loggers) interfaces.LoggingConfiguration
TestLoggingConfigWithLoggers returns a LoggingConfiguration with the specified Loggers.
func WithTempFileContaining ¶
WithTempFileContaining runs the specified function with the file path of a temporary file that has been created with the specified data.
Types ¶
type CapturingDataStore ¶
type CapturingDataStore struct {
// contains filtered or unexported fields
}
CapturingDataStore is a DataStore implementation that records update operations for testing.
func NewCapturingDataStore ¶
func NewCapturingDataStore(realStore interfaces.DataStore) *CapturingDataStore
NewCapturingDataStore creates an instance of CapturingDataStore.
func (*CapturingDataStore) Close ¶
func (d *CapturingDataStore) Close() error
Close in this test type is a no-op.
func (*CapturingDataStore) Get ¶
func (d *CapturingDataStore) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDescriptor, error)
Get is a standard DataStore method.
func (*CapturingDataStore) GetAll ¶
func (d *CapturingDataStore) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error)
GetAll is a standard DataStore method.
func (*CapturingDataStore) Init ¶
func (d *CapturingDataStore) Init(allData []ldstoretypes.Collection) error
Init is a standard DataStore method.
func (*CapturingDataStore) IsInitialized ¶
func (d *CapturingDataStore) IsInitialized() bool
IsInitialized in this test type always returns true.
func (*CapturingDataStore) IsStatusMonitoringEnabled ¶
func (d *CapturingDataStore) IsStatusMonitoringEnabled() bool
IsStatusMonitoringEnabled in this test type returns true by default, but can be changed with SetStatusMonitoringEnabled.
func (*CapturingDataStore) SetFakeError ¶
func (d *CapturingDataStore) SetFakeError(fakeError error)
SetFakeError causes subsequent Init or Upsert calls to return an error.
func (*CapturingDataStore) SetStatusMonitoringEnabled ¶
func (d *CapturingDataStore) SetStatusMonitoringEnabled(statusMonitoringEnabled bool)
SetStatusMonitoringEnabled changes the value returned by IsStatusMonitoringEnabled.
func (*CapturingDataStore) Upsert ¶
func (d *CapturingDataStore) Upsert( kind ldstoretypes.DataKind, key string, newItem ldstoretypes.ItemDescriptor, ) (bool, error)
Upsert in this test type does nothing but capture its parameters.
func (*CapturingDataStore) WaitForDelete ¶
func (d *CapturingDataStore) WaitForDelete( t *testing.T, kind ldstoretypes.DataKind, key string, version int, timeout time.Duration, )
WaitForDelete waits for an Upsert call that is expected to delete a data item.
func (*CapturingDataStore) WaitForInit ¶
func (d *CapturingDataStore) WaitForInit( t *testing.T, data *ldservices.ServerSDKData, timeout time.Duration, )
WaitForInit waits for an Init call and verifies that it matches the expected data.
func (*CapturingDataStore) WaitForNextInit ¶
func (d *CapturingDataStore) WaitForNextInit( t *testing.T, timeout time.Duration, ) []ldstoretypes.Collection
WaitForNextInit waits for an Init call.
func (*CapturingDataStore) WaitForNextUpsert ¶
func (d *CapturingDataStore) WaitForNextUpsert( t *testing.T, timeout time.Duration, ) UpsertParams
WaitForNextUpsert waits for an Upsert call.
func (*CapturingDataStore) WaitForUpsert ¶
func (d *CapturingDataStore) WaitForUpsert( t *testing.T, kind ldstoretypes.DataKind, key string, version int, timeout time.Duration, ) UpsertParams
WaitForUpsert waits for an Upsert call and verifies that it matches the expected data.
type CapturingEventProcessor ¶
type CapturingEventProcessor struct {
Events []interface{}
}
CapturingEventProcessor is a test implementation of EventProcessor that accumulates all events.
func (*CapturingEventProcessor) Close ¶
func (c *CapturingEventProcessor) Close() error
func (*CapturingEventProcessor) Flush ¶
func (c *CapturingEventProcessor) Flush()
func (*CapturingEventProcessor) RecordAliasEvent ¶ added in v5.2.0
func (c *CapturingEventProcessor) RecordAliasEvent(e ldevents.AliasEvent)
func (*CapturingEventProcessor) RecordCustomEvent ¶
func (c *CapturingEventProcessor) RecordCustomEvent(e ldevents.CustomEvent)
func (*CapturingEventProcessor) RecordFeatureRequestEvent ¶
func (c *CapturingEventProcessor) RecordFeatureRequestEvent(e ldevents.FeatureRequestEvent)
func (*CapturingEventProcessor) RecordIdentifyEvent ¶
func (c *CapturingEventProcessor) RecordIdentifyEvent(e ldevents.IdentifyEvent)
type DataSetBuilder ¶
type DataSetBuilder struct {
// contains filtered or unexported fields
}
DataSetBuilder is a helper for creating collections of flags and segments.
func NewDataSetBuilder ¶
func NewDataSetBuilder() *DataSetBuilder
NewDataSetBuilder creates a DataSetBuilder.
func (*DataSetBuilder) Build ¶
func (d *DataSetBuilder) Build() []ldstoretypes.Collection
Build returns the built data sest.
func (*DataSetBuilder) Flags ¶
func (d *DataSetBuilder) Flags(flags ...ldmodel.FeatureFlag) *DataSetBuilder
Flags adds flags to the data set.
func (*DataSetBuilder) Segments ¶
func (d *DataSetBuilder) Segments(segments ...ldmodel.Segment) *DataSetBuilder
Segments adds segments to the data set.
func (*DataSetBuilder) ToServerSDKData ¶
func (d *DataSetBuilder) ToServerSDKData() *ldservices.ServerSDKData
ToServerSDKData converts the data set to the format used by the ldservices helpers.
type DataSourceFactoryThatExposesUpdater ¶
type DataSourceFactoryThatExposesUpdater struct { UnderlyingFactory interfaces.DataSourceFactory DataSourceUpdates interfaces.DataSourceUpdates }
DataSourceFactoryThatExposesUpdater is a test implementation of DataSourceFactory that captures the DataSourceUpdates instance provided by LDClient.
func (*DataSourceFactoryThatExposesUpdater) CreateDataSource ¶
func (f *DataSourceFactoryThatExposesUpdater) CreateDataSource( context interfaces.ClientContext, dataSourceUpdates interfaces.DataSourceUpdates, ) (interfaces.DataSource, error)
type DataSourceFactoryWithData ¶
type DataSourceFactoryWithData struct {
Data []ldstoretypes.Collection
}
DataSourceFactoryWithData is a test implementation of DataSourceFactory that will cause the data source to provide a specific set of data when it starts.
func (DataSourceFactoryWithData) CreateDataSource ¶
func (f DataSourceFactoryWithData) CreateDataSource( context interfaces.ClientContext, dataSourceUpdates interfaces.DataSourceUpdates, ) (interfaces.DataSource, error)
type DataStoreFactoryThatExposesUpdater ¶
type DataStoreFactoryThatExposesUpdater struct { UnderlyingFactory interfaces.DataStoreFactory DataStoreUpdates interfaces.DataStoreUpdates }
DataStoreFactoryThatExposesUpdater is a test implementation of DataStoreFactory that captures the DataStoreUpdates instance provided by LDClient.
func (*DataStoreFactoryThatExposesUpdater) CreateDataStore ¶
func (f *DataStoreFactoryThatExposesUpdater) CreateDataStore( context interfaces.ClientContext, dataStoreUpdates interfaces.DataStoreUpdates, ) (interfaces.DataStore, error)
type MockBigSegmentStore ¶ added in v5.5.0
type MockBigSegmentStore struct {
// contains filtered or unexported fields
}
MockBigSegmentStore is a minimal mock implementation of BigSegmentStore. Currently it only supports specifying the metadata and simulating an error for metadata queries.
func (*MockBigSegmentStore) Close ¶ added in v5.5.0
func (m *MockBigSegmentStore) Close() error
func (*MockBigSegmentStore) GetMetadata ¶ added in v5.5.0
func (m *MockBigSegmentStore) GetMetadata() (interfaces.BigSegmentStoreMetadata, error)
func (*MockBigSegmentStore) GetUserMembership ¶ added in v5.5.0
func (m *MockBigSegmentStore) GetUserMembership( userHash string, ) (interfaces.BigSegmentMembership, error)
func (*MockBigSegmentStore) TestGetMembershipQueries ¶ added in v5.5.0
func (m *MockBigSegmentStore) TestGetMembershipQueries() []string
func (*MockBigSegmentStore) TestGetMetadataQueriesCh ¶ added in v5.6.0
func (m *MockBigSegmentStore) TestGetMetadataQueriesCh() <-chan struct{}
func (*MockBigSegmentStore) TestSetMembership ¶ added in v5.5.0
func (m *MockBigSegmentStore) TestSetMembership( userHash string, membership interfaces.BigSegmentMembership, )
func (*MockBigSegmentStore) TestSetMembershipError ¶ added in v5.5.0
func (m *MockBigSegmentStore) TestSetMembershipError(err error)
func (*MockBigSegmentStore) TestSetMetadataState ¶ added in v5.5.0
func (m *MockBigSegmentStore) TestSetMetadataState( md interfaces.BigSegmentStoreMetadata, err error, )
func (*MockBigSegmentStore) TestSetMetadataToCurrentTime ¶ added in v5.5.0
func (m *MockBigSegmentStore) TestSetMetadataToCurrentTime()
type MockDataItem ¶
MockDataItem is a test replacement for FeatureFlag/Segment.
func (MockDataItem) ToItemDescriptor ¶
func (m MockDataItem) ToItemDescriptor() ldstoretypes.ItemDescriptor
ToItemDescriptor converts the test item to a StoreItemDescriptor.
func (MockDataItem) ToKeyedItemDescriptor ¶
func (m MockDataItem) ToKeyedItemDescriptor() ldstoretypes.KeyedItemDescriptor
ToKeyedItemDescriptor converts the test item to a StoreKeyedItemDescriptor.
func (MockDataItem) ToSerializedItemDescriptor ¶
func (m MockDataItem) ToSerializedItemDescriptor() ldstoretypes.SerializedItemDescriptor
ToSerializedItemDescriptor converts the test item to a StoreSerializedItemDescriptor.
type MockDataSourceUpdates ¶
type MockDataSourceUpdates struct { DataStore *CapturingDataStore Statuses chan interfaces.DataSourceStatus // contains filtered or unexported fields }
MockDataSourceUpdates is a mock implementation of DataSourceUpdates for testing data sources.
func NewMockDataSourceUpdates ¶
func NewMockDataSourceUpdates(realStore interfaces.DataStore) *MockDataSourceUpdates
NewMockDataSourceUpdates creates an instance of MockDataSourceUpdates.
The DataStoreStatusProvider can be nil if we are not doing a test that requires manipulation of that component.
func (*MockDataSourceUpdates) GetDataStoreStatusProvider ¶
func (d *MockDataSourceUpdates) GetDataStoreStatusProvider() interfaces.DataStoreStatusProvider
GetDataStoreStatusProvider returns a stub implementation that does not have full functionality but enough to test a data source with.
func (*MockDataSourceUpdates) Init ¶
func (d *MockDataSourceUpdates) Init(allData []ldstoretypes.Collection) bool
Init in this test implementation, delegates to d.DataStore.CapturedUpdates.
func (*MockDataSourceUpdates) RequireStatus ¶
func (d *MockDataSourceUpdates) RequireStatus(t *testing.T) interfaces.DataSourceStatus
RequireStatus blocks until a new data source status is available.
func (*MockDataSourceUpdates) RequireStatusOf ¶
func (d *MockDataSourceUpdates) RequireStatusOf( t *testing.T, newState interfaces.DataSourceState, ) interfaces.DataSourceStatus
RequireStatusOf blocks until a new data source status is available, and verifies its state.
func (*MockDataSourceUpdates) UpdateStatus ¶
func (d *MockDataSourceUpdates) UpdateStatus( newState interfaces.DataSourceState, newError interfaces.DataSourceErrorInfo, )
UpdateStatus in this test implementation, pushes a value onto the Statuses channel.
func (*MockDataSourceUpdates) UpdateStoreStatus ¶
func (d *MockDataSourceUpdates) UpdateStoreStatus(newStatus interfaces.DataStoreStatus)
UpdateStoreStatus simulates a change in the data store status.
func (*MockDataSourceUpdates) Upsert ¶
func (d *MockDataSourceUpdates) Upsert( kind ldstoretypes.DataKind, key string, newItem ldstoretypes.ItemDescriptor, ) bool
Upsert in this test implementation, delegates to d.DataStore.CapturedUpdates.
type MockDatabaseInstance ¶
type MockDatabaseInstance struct {
// contains filtered or unexported fields
}
MockDatabaseInstance can be used with MockPersistentDataStore to simulate multiple data store instances sharing the same underlying data space.
func NewMockDatabaseInstance ¶
func NewMockDatabaseInstance() *MockDatabaseInstance
NewMockDatabaseInstance creates an instance of MockDatabaseInstance.
func (*MockDatabaseInstance) Clear ¶
func (db *MockDatabaseInstance) Clear(prefix string)
Clear removes all shared data.
type MockPersistentDataStore ¶
type MockPersistentDataStore struct { InitQueriedCount int // contains filtered or unexported fields }
MockPersistentDataStore is a test implementation of PersistentDataStore.
func NewMockPersistentDataStore ¶
func NewMockPersistentDataStore() *MockPersistentDataStore
NewMockPersistentDataStore creates a test implementation of a persistent data store.
func NewMockPersistentDataStoreWithPrefix ¶
func NewMockPersistentDataStoreWithPrefix( db *MockDatabaseInstance, prefix string, ) *MockPersistentDataStore
NewMockPersistentDataStoreWithPrefix creates a test implementation of a persistent data store that uses a MockDatabaseInstance to simulate a shared database.
func (*MockPersistentDataStore) Close ¶
func (m *MockPersistentDataStore) Close() error
Close is a standard PersistentDataStore method.
func (*MockPersistentDataStore) EnableInstrumentedQueries ¶
func (m *MockPersistentDataStore) EnableInstrumentedQueries(queryDelay time.Duration) <-chan struct{}
EnableInstrumentedQueries puts the test store into a mode where all get operations begin by posting a signal to a channel and then waiting for some amount of time, to test coalescing of requests.
func (*MockPersistentDataStore) ForceGet ¶
func (m *MockPersistentDataStore) ForceGet( kind ldstoretypes.DataKind, key string, ) ldstoretypes.SerializedItemDescriptor
ForceGet retrieves a serialized item directly from the test data with no other processing.
func (*MockPersistentDataStore) ForceRemove ¶
func (m *MockPersistentDataStore) ForceRemove(kind ldstoretypes.DataKind, key string)
ForceRemove deletes an item from the test data.
func (*MockPersistentDataStore) ForceSet ¶
func (m *MockPersistentDataStore) ForceSet( kind ldstoretypes.DataKind, key string, item ldstoretypes.SerializedItemDescriptor, )
ForceSet directly modifies an item in the test data.
func (*MockPersistentDataStore) ForceSetInited ¶
func (m *MockPersistentDataStore) ForceSetInited(inited bool)
ForceSetInited changes the value that will be returned by IsInitialized().
func (*MockPersistentDataStore) Get ¶
func (m *MockPersistentDataStore) Get( kind ldstoretypes.DataKind, key string, ) (ldstoretypes.SerializedItemDescriptor, error)
Get is a standard PersistentDataStore method.
func (*MockPersistentDataStore) GetAll ¶
func (m *MockPersistentDataStore) GetAll( kind ldstoretypes.DataKind, ) ([]ldstoretypes.KeyedSerializedItemDescriptor, error)
GetAll is a standard PersistentDataStore method.
func (*MockPersistentDataStore) Init ¶
func (m *MockPersistentDataStore) Init(allData []ldstoretypes.SerializedCollection) error
Init is a standard PersistentDataStore method.
func (*MockPersistentDataStore) IsInitialized ¶
func (m *MockPersistentDataStore) IsInitialized() bool
IsInitialized is a standard PersistentDataStore method.
func (*MockPersistentDataStore) IsStoreAvailable ¶
func (m *MockPersistentDataStore) IsStoreAvailable() bool
IsStoreAvailable is a standard PersistentDataStore method.
func (*MockPersistentDataStore) SetAvailable ¶
func (m *MockPersistentDataStore) SetAvailable(available bool)
SetAvailable changes the value that will be returned by IsStoreAvailable().
func (*MockPersistentDataStore) SetFakeError ¶
func (m *MockPersistentDataStore) SetFakeError(fakeError error)
SetFakeError causes subsequent store operations to return an error.
func (*MockPersistentDataStore) SetPersistOnlyAsString ¶
func (m *MockPersistentDataStore) SetPersistOnlyAsString(value bool)
SetPersistOnlyAsString sets whether the mock data store should behave like our Redis implementation, where the item version is *not* persisted separately from the serialized item string (so the latter must be parsed to get the version). If this is false (the default), it behaves instead like our DynamoDB implementation, where the version metadata exists separately from the serialized string.
func (*MockPersistentDataStore) SetTestTxHook ¶
func (m *MockPersistentDataStore) SetTestTxHook(hook func())
SetTestTxHook sets a callback function that will be called during updates, to support the concurrent modification tests in PersistentDataStoreTestSuite.
func (*MockPersistentDataStore) Upsert ¶
func (m *MockPersistentDataStore) Upsert( kind ldstoretypes.DataKind, key string, newItem ldstoretypes.SerializedItemDescriptor, ) (bool, error)
Upsert is a standard PersistentDataStore method.
type SingleBigSegmentStoreFactory ¶ added in v5.5.0
type SingleBigSegmentStoreFactory struct {
Store *MockBigSegmentStore
}
SingleBigSegmentStoreFactory is an BigSegmentStoreFactory that returns an existing instance.
func (SingleBigSegmentStoreFactory) CreateBigSegmentStore ¶ added in v5.5.0
func (f SingleBigSegmentStoreFactory) CreateBigSegmentStore(interfaces.ClientContext) ( interfaces.BigSegmentStore, error)
type SingleDataStoreFactory ¶
type SingleDataStoreFactory struct {
Instance interfaces.DataStore
}
SingleDataStoreFactory is a test implementation of DataStoreFactory that always returns the same pre-existing instance.
func (SingleDataStoreFactory) CreateDataStore ¶
func (f SingleDataStoreFactory) CreateDataStore( context interfaces.ClientContext, dataStoreUpdates interfaces.DataStoreUpdates, ) (interfaces.DataStore, error)
type SingleEventProcessorFactory ¶
type SingleEventProcessorFactory struct {
Instance ldevents.EventProcessor
}
SingleEventProcessorFactory is a test implementation of EventProcessorFactory that always returns the same pre-existing instance.
func (SingleEventProcessorFactory) CreateEventProcessor ¶
func (f SingleEventProcessorFactory) CreateEventProcessor( context interfaces.ClientContext, ) (ldevents.EventProcessor, error)
type SinglePersistentDataStoreFactory ¶
type SinglePersistentDataStoreFactory struct {
Instance interfaces.PersistentDataStore
}
SinglePersistentDataStoreFactory is a test implementation of PersistentDataStoreFactory that always returns the same pre-existing instance.
func (SinglePersistentDataStoreFactory) CreatePersistentDataStore ¶
func (f SinglePersistentDataStoreFactory) CreatePersistentDataStore( context interfaces.ClientContext, ) (interfaces.PersistentDataStore, error)
type UpsertParams ¶
type UpsertParams struct { Kind ldstoretypes.DataKind Key string Item ldstoretypes.ItemDescriptor }
UpsertParams holds the parameters of an Upsert operation captured by CapturingDataStore.