MockData is an instance of ld.StoreDataKind corresponding to MockDataItem.
var MockData = mockDataKind{/* contains filtered or unexported fields */}
MockOtherData is an instance of ld.StoreDataKind corresponding to another flavor of MockDataItem.
var MockOtherData = mockDataKind{/* contains filtered or unexported fields */}
func AssertNotNil(i interface{})
AssertNotNil forces a panic if the specified value is nil (either a nil interface value, or a nil pointer).
func DataSourceThatIsAlwaysInitialized() subsystems.ComponentConfigurer[subsystems.DataSource]
DataSourceThatIsAlwaysInitialized returns a test component factory that produces a data source that immediately reports success on startup, although it does not provide any data.
func DataSourceThatNeverInitializes() subsystems.ComponentConfigurer[subsystems.DataSource]
DataSourceThatNeverInitializes returns a test component factory that produces a data source that immediately starts up in a failed state and does not provide any data.
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 MakeMockDataSet(items ...MockDataItem) []ldstoretypes.Collection
MakeMockDataSet constructs a data set to be passed to a data store's Init method.
func MakeSerializedMockDataSet(items ...MockDataItem) []ldstoretypes.SerializedCollection
MakeSerializedMockDataSet constructs a data set to be passed to a persistent data store's Init method.
CapturingDataStore is a DataStore implementation that records update operations for testing.
type CapturingDataStore struct {
// contains filtered or unexported fields
}
func NewCapturingDataStore(realStore subsystems.DataStore) *CapturingDataStore
NewCapturingDataStore creates an instance of CapturingDataStore.
func (d *CapturingDataStore) Close() error
Close in this test type is a no-op.
func (d *CapturingDataStore) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDescriptor, error)
Get is a standard DataStore method.
func (d *CapturingDataStore) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error)
GetAll is a standard DataStore method.
func (d *CapturingDataStore) Init(allData []ldstoretypes.Collection) error
Init is a standard DataStore method.
func (d *CapturingDataStore) IsInitialized() bool
IsInitialized in this test type always returns true.
func (d *CapturingDataStore) IsStatusMonitoringEnabled() bool
IsStatusMonitoringEnabled in this test type returns true by default, but can be changed with SetStatusMonitoringEnabled.
func (d *CapturingDataStore) SetFakeError(fakeError error)
SetFakeError causes subsequent Init or Upsert calls to return an error.
func (d *CapturingDataStore) SetStatusMonitoringEnabled(statusMonitoringEnabled bool)
SetStatusMonitoringEnabled changes the value returned by IsStatusMonitoringEnabled.
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 (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 (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 (d *CapturingDataStore) WaitForNextInit( t *testing.T, timeout time.Duration, ) []ldstoretypes.Collection
WaitForNextInit waits for an Init call.
func (d *CapturingDataStore) WaitForNextUpsert( t *testing.T, timeout time.Duration, ) UpsertParams
WaitForNextUpsert waits for an Upsert call.
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.
CapturingEventProcessor is a test implementation of EventProcessor that accumulates all events.
type CapturingEventProcessor struct { Events []interface{} }
func (c *CapturingEventProcessor) Close() error
func (c *CapturingEventProcessor) Flush()
func (c *CapturingEventProcessor) FlushBlocking(time.Duration) bool
func (c *CapturingEventProcessor) RecordCustomEvent(e ldevents.CustomEventData)
func (c *CapturingEventProcessor) RecordEvaluation(e ldevents.EvaluationData)
func (c *CapturingEventProcessor) RecordIdentifyEvent(e ldevents.IdentifyEventData)
func (c *CapturingEventProcessor) RecordRawEvent(e json.RawMessage)
ComponentConfigurerThatCapturesClientContext is a test decorator for a ComponentConfigurer that allows tests to see the ClientContext that was passed to it.
type ComponentConfigurerThatCapturesClientContext[T any] struct { Configurer subsystems.ComponentConfigurer[T] ReceivedClientContext subsystems.ClientContext }
func (c *ComponentConfigurerThatCapturesClientContext[T]) Build(clientContext subsystems.ClientContext) (T, error)
ComponentConfigurerThatReturnsError is a test implementation of ComponentConfigurer that always returns an error.
type ComponentConfigurerThatReturnsError[T any] struct { Err error }
func (c ComponentConfigurerThatReturnsError[T]) Build(clientContext subsystems.ClientContext) (T, error)
DataSourceFactoryWithData is a test implementation of ComponentConfigurer that will cause the data source to provide a specific set of data when it starts.
type DataSourceFactoryWithData struct { Data []ldstoretypes.Collection }
func (f DataSourceFactoryWithData) Build( context subsystems.ClientContext, ) (subsystems.DataSource, error)
MockBigSegmentStore is a minimal mock implementation of BigSegmentStore. Currently it only supports specifying the metadata and simulating an error for metadata queries.
type MockBigSegmentStore struct {
// contains filtered or unexported fields
}
func (m *MockBigSegmentStore) Close() error
func (m *MockBigSegmentStore) GetMembership( contextHash string, ) (subsystems.BigSegmentMembership, error)
func (m *MockBigSegmentStore) GetMetadata() (subsystems.BigSegmentStoreMetadata, error)
func (m *MockBigSegmentStore) TestGetMembershipQueries() []string
func (m *MockBigSegmentStore) TestGetMetadataQueriesCh() <-chan struct{}
func (m *MockBigSegmentStore) TestSetMembership( contextHash string, membership subsystems.BigSegmentMembership, )
func (m *MockBigSegmentStore) TestSetMembershipError(err error)
func (m *MockBigSegmentStore) TestSetMetadataState( md subsystems.BigSegmentStoreMetadata, err error, )
func (m *MockBigSegmentStore) TestSetMetadataToCurrentTime()
MockDataItem is a test replacement for FeatureFlag/Segment.
type MockDataItem struct { Key string Version int Deleted bool Name string IsOtherKind bool }
func (m MockDataItem) ToItemDescriptor() ldstoretypes.ItemDescriptor
ToItemDescriptor converts the test item to a StoreItemDescriptor.
func (m MockDataItem) ToKeyedItemDescriptor() ldstoretypes.KeyedItemDescriptor
ToKeyedItemDescriptor converts the test item to a StoreKeyedItemDescriptor.
func (m MockDataItem) ToSerializedItemDescriptor() ldstoretypes.SerializedItemDescriptor
ToSerializedItemDescriptor converts the test item to a StoreSerializedItemDescriptor.
MockDataSourceUpdates is a mock implementation of DataSourceUpdates for testing data sources.
type MockDataSourceUpdates struct { DataStore *CapturingDataStore Statuses chan interfaces.DataSourceStatus // contains filtered or unexported fields }
func NewMockDataSourceUpdates(realStore subsystems.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 (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 (d *MockDataSourceUpdates) Init(allData []ldstoretypes.Collection) bool
Init in this test implementation, delegates to d.DataStore.CapturedUpdates.
func (d *MockDataSourceUpdates) RequireStatus(t *testing.T) interfaces.DataSourceStatus
RequireStatus blocks until a new data source status is available.
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 (d *MockDataSourceUpdates) UpdateStatus( newState interfaces.DataSourceState, newError interfaces.DataSourceErrorInfo, )
UpdateStatus in this test implementation, pushes a value onto the Statuses channel.
func (d *MockDataSourceUpdates) UpdateStoreStatus(newStatus interfaces.DataStoreStatus)
UpdateStoreStatus simulates a change in the data store status.
func (d *MockDataSourceUpdates) Upsert( kind ldstoretypes.DataKind, key string, newItem ldstoretypes.ItemDescriptor, ) bool
Upsert in this test implementation, delegates to d.DataStore.CapturedUpdates.
MockDatabaseInstance can be used with MockPersistentDataStore to simulate multiple data store instances sharing the same underlying data space.
type MockDatabaseInstance struct {
// contains filtered or unexported fields
}
func NewMockDatabaseInstance() *MockDatabaseInstance
NewMockDatabaseInstance creates an instance of MockDatabaseInstance.
func (db *MockDatabaseInstance) Clear(prefix string)
Clear removes all shared data.
MockPersistentDataStore is a test implementation of PersistentDataStore.
type MockPersistentDataStore struct { InitQueriedCount int // contains filtered or unexported fields }
func NewMockPersistentDataStore() *MockPersistentDataStore
NewMockPersistentDataStore creates a test implementation of a persistent data store.
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 (m *MockPersistentDataStore) Close() error
Close is a standard PersistentDataStore method.
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 (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 (m *MockPersistentDataStore) ForceRemove(kind ldstoretypes.DataKind, key string)
ForceRemove deletes an item from the test data.
func (m *MockPersistentDataStore) ForceSet( kind ldstoretypes.DataKind, key string, item ldstoretypes.SerializedItemDescriptor, )
ForceSet directly modifies an item in the test data.
func (m *MockPersistentDataStore) ForceSetInited(inited bool)
ForceSetInited changes the value that will be returned by IsInitialized().
func (m *MockPersistentDataStore) Get( kind ldstoretypes.DataKind, key string, ) (ldstoretypes.SerializedItemDescriptor, error)
Get is a standard PersistentDataStore method.
func (m *MockPersistentDataStore) GetAll( kind ldstoretypes.DataKind, ) ([]ldstoretypes.KeyedSerializedItemDescriptor, error)
GetAll is a standard PersistentDataStore method.
func (m *MockPersistentDataStore) Init(allData []ldstoretypes.SerializedCollection) error
Init is a standard PersistentDataStore method.
func (m *MockPersistentDataStore) IsInitialized() bool
IsInitialized is a standard PersistentDataStore method.
func (m *MockPersistentDataStore) IsStoreAvailable() bool
IsStoreAvailable is a standard PersistentDataStore method.
func (m *MockPersistentDataStore) SetAvailable(available bool)
SetAvailable changes the value that will be returned by IsStoreAvailable().
func (m *MockPersistentDataStore) SetFakeError(fakeError error)
SetFakeError causes subsequent store operations to return an error.
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 (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 (m *MockPersistentDataStore) Upsert( kind ldstoretypes.DataKind, key string, newItem ldstoretypes.SerializedItemDescriptor, ) (bool, error)
Upsert is a standard PersistentDataStore method.
SingleComponentConfigurer is a test implementation of ComponentConfigurer that always returns the same pre-existing instance.
type SingleComponentConfigurer[T any] struct { Instance T }
func (c SingleComponentConfigurer[T]) Build(clientContext subsystems.ClientContext) (T, error)
UpsertParams holds the parameters of an Upsert operation captured by CapturingDataStore.
type UpsertParams struct { Kind ldstoretypes.DataKind Key string Item ldstoretypes.ItemDescriptor }