Documentation ¶
Overview ¶
Package mocks contains mocks/spies used within SDK unit tests.
Index ¶
- Variables
- func AssertNotNil(i interface{})
- func DataSourceThatIsAlwaysInitialized() subsystems.ComponentConfigurer[subsystems.DataSource]
- func DataSourceThatNeverInitializes() subsystems.ComponentConfigurer[subsystems.DataSource]
- func ExpectBigSegmentStoreStatus(t *testing.T, statusCh <-chan interfaces.BigSegmentStoreStatus, ...)
- func MakeMockDataSet(items ...MockDataItem) []ldstoretypes.Collection
- func MakeSerializedMockDataSet(items ...MockDataItem) []ldstoretypes.SerializedCollection
- 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) 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)
- type ComponentConfigurerThatCapturesClientContext
- type ComponentConfigurerThatReturnsError
- type DataSourceFactoryWithData
- type MockBigSegmentStore
- 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()
- 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 SingleComponentConfigurer
- 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 DataSourceThatIsAlwaysInitialized ¶
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 ¶
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 ¶
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 ¶
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.
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 subsystems.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) FlushBlocking ¶
func (c *CapturingEventProcessor) FlushBlocking(time.Duration) bool
func (*CapturingEventProcessor) RecordCustomEvent ¶
func (c *CapturingEventProcessor) RecordCustomEvent(e ldevents.CustomEventData)
func (*CapturingEventProcessor) RecordEvaluation ¶
func (c *CapturingEventProcessor) RecordEvaluation(e ldevents.EvaluationData)
func (*CapturingEventProcessor) RecordIdentifyEvent ¶
func (c *CapturingEventProcessor) RecordIdentifyEvent(e ldevents.IdentifyEventData)
func (*CapturingEventProcessor) RecordRawEvent ¶
func (c *CapturingEventProcessor) RecordRawEvent(e json.RawMessage)
type ComponentConfigurerThatCapturesClientContext ¶
type ComponentConfigurerThatCapturesClientContext[T any] struct { Configurer subsystems.ComponentConfigurer[T] ReceivedClientContext subsystems.ClientContext }
ComponentConfigurerThatCapturesClientContext is a test decorator for a ComponentConfigurer that allows tests to see the ClientContext that was passed to it.
func (*ComponentConfigurerThatCapturesClientContext[T]) Build ¶
func (c *ComponentConfigurerThatCapturesClientContext[T]) Build(clientContext subsystems.ClientContext) (T, error)
type ComponentConfigurerThatReturnsError ¶
ComponentConfigurerThatReturnsError is a test implementation of ComponentConfigurer that always returns an error.
func (ComponentConfigurerThatReturnsError[T]) Build ¶
func (c ComponentConfigurerThatReturnsError[T]) Build(clientContext subsystems.ClientContext) (T, error)
type DataSourceFactoryWithData ¶
type DataSourceFactoryWithData struct {
Data []ldstoretypes.Collection
}
DataSourceFactoryWithData is a test implementation of ComponentConfigurer that will cause the data source to provide a specific set of data when it starts.
func (DataSourceFactoryWithData) Build ¶
func (f DataSourceFactoryWithData) Build( context subsystems.ClientContext, ) (subsystems.DataSource, error)
type MockBigSegmentStore ¶
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 ¶
func (m *MockBigSegmentStore) Close() error
func (*MockBigSegmentStore) GetMembership ¶
func (m *MockBigSegmentStore) GetMembership( contextHash string, ) (subsystems.BigSegmentMembership, error)
func (*MockBigSegmentStore) GetMetadata ¶
func (m *MockBigSegmentStore) GetMetadata() (subsystems.BigSegmentStoreMetadata, error)
func (*MockBigSegmentStore) TestGetMembershipQueries ¶
func (m *MockBigSegmentStore) TestGetMembershipQueries() []string
func (*MockBigSegmentStore) TestGetMetadataQueriesCh ¶
func (m *MockBigSegmentStore) TestGetMetadataQueriesCh() <-chan struct{}
func (*MockBigSegmentStore) TestSetMembership ¶
func (m *MockBigSegmentStore) TestSetMembership( contextHash string, membership subsystems.BigSegmentMembership, )
func (*MockBigSegmentStore) TestSetMembershipError ¶
func (m *MockBigSegmentStore) TestSetMembershipError(err error)
func (*MockBigSegmentStore) TestSetMetadataState ¶
func (m *MockBigSegmentStore) TestSetMetadataState( md subsystems.BigSegmentStoreMetadata, err error, )
func (*MockBigSegmentStore) TestSetMetadataToCurrentTime ¶
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 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 (*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 SingleComponentConfigurer ¶
type SingleComponentConfigurer[T any] struct { Instance T }
SingleComponentConfigurer is a test implementation of ComponentConfigurer that always returns the same pre-existing instance.
func (SingleComponentConfigurer[T]) Build ¶
func (c SingleComponentConfigurer[T]) Build(clientContext subsystems.ClientContext) (T, 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.