mocks

package
v7.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package mocks contains mocks/spies used within SDK unit tests.

Index

Constants

This section is empty.

Variables

View Source
var MockData = mockDataKind{/* contains filtered or unexported fields */}

MockData is an instance of ld.StoreDataKind corresponding to MockDataItem.

View Source
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

Get is a standard DataStore method.

func (*CapturingDataStore) GetAll

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

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) RecordMigrationOpEvent

func (c *CapturingEventProcessor) RecordMigrationOpEvent(e ldevents.MigrationOpEventData)

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

Build builds the component.

type ComponentConfigurerThatReturnsError

type ComponentConfigurerThatReturnsError[T any] struct {
	Err error
}

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)

Build builds the component.

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

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 (*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

type MockDataItem struct {
	Key         string
	Version     int
	Deleted     bool
	Name        string
	IsOtherKind bool
}

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

Init in this test implementation, delegates to d.DataStore.CapturedUpdates.

func (*MockDataSourceUpdates) RequireStatus

RequireStatus blocks until a new data source status is available.

func (*MockDataSourceUpdates) RequireStatusOf

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

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

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

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

Get is a standard PersistentDataStore method.

func (*MockPersistentDataStore) GetAll

GetAll is a standard PersistentDataStore method.

func (*MockPersistentDataStore) Init

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

Upsert is a standard PersistentDataStore method.

type RequestAllResponse

type RequestAllResponse struct {
	Data   []ldstoretypes.Collection
	Cached bool
	Err    error
}

RequestAllResponse is used to inject custom responses into the Requester, which will subsequently return them to the object under test.

type Requester

type Requester struct {
	RequestAllRespCh chan RequestAllResponse
	PollsCh          chan struct{}
	CloserCh         chan struct{}
}

Requester is a mock used in polling_data_source_test.go, to satisfy the datasource.Requester interface (used by PollingProcessor). Its purpose is to allow the PollingProcessor to be tested without involving actual HTTP operations.

func NewPollingRequester

func NewPollingRequester() *Requester

NewPollingRequester constructs a Requester.

func (*Requester) BaseURI

func (r *Requester) BaseURI() string

BaseURI exists to fulfil the datasource.Requester interface; here it returns an empty string.

func (*Requester) Close

func (r *Requester) Close()

Close closes the Requester's CloserCh.

func (*Requester) FilterKey

func (r *Requester) FilterKey() string

FilterKey exists to fulfil the datasource.Requester interface; here it returns an empty string.

func (*Requester) Request

func (r *Requester) Request() ([]ldstoretypes.Collection, bool, error)

Request blocks until a mock request is available on the RequestAllRespCh, or until closing via Close().

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)

Build builds the component.

type UpsertParams

type UpsertParams struct {
	Kind ldstoretypes.DataKind
	Key  string
	Item ldstoretypes.ItemDescriptor
}

UpsertParams holds the parameters of an Upsert operation captured by CapturingDataStore.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL