sdktests

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package sdktests contains the domain-specific SDK test logic.

Tests in this package use other packages as follows:

ldtest: the basic test scope framework

mockd: mock LaunchDarkly service components

servicedef: types used in communication with an SDK test service

testdata: test data file schemas and loader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64DecodedData added in v1.7.0

func Base64DecodedData() m.MatcherTransform

func EqualReason added in v1.4.0

func EqualReason(reason ldreason.EvaluationReason) m.Matcher

EqualReason is a type-safe replacement for m.Equal(EvaluationReason) that also provides better failure output, by treating it as a JSON object-- since the default implementation of String() for EvaluationReason returns a shorter string that doesn't include every property.

func EvalAllFlagsStateMap added in v1.0.0

func EvalAllFlagsStateMap() m.MatcherTransform

func EvalAllFlagsValueForKeyShouldEqual added in v1.0.0

func EvalAllFlagsValueForKeyShouldEqual(key string, value ldvalue.Value) m.Matcher

func EvalResponseReason

func EvalResponseReason() m.MatcherTransform

func EvalResponseValue

func EvalResponseValue() m.MatcherTransform

func EvalResponseVariation

func EvalResponseVariation() m.MatcherTransform

func EventHasKind

func EventHasKind(kind string) m.Matcher

func HasAnyCreationDate added in v1.1.2

func HasAnyCreationDate() m.Matcher

func HasAuthorizationHeader added in v1.6.1

func HasAuthorizationHeader(authKey string) m.Matcher

HasAuthorizationHeader is a matcher for an http.Header map that verifies that the Authorization header is present and contains the specified key. Some SDKs send just the raw key, while others prefix it with an "api_key" scheme identifier; the latter is more technically correct, but we need to allow both since LD allows both.

func HasContextKind added in v1.1.2

func HasContextKind(user lduser.User) m.Matcher

func HasNoAuthorizationHeader added in v1.6.1

func HasNoAuthorizationHeader() m.Matcher

func HasNoUserKeyProperty added in v1.1.2

func HasNoUserKeyProperty() m.Matcher

func HasNoUserObject added in v1.1.2

func HasNoUserObject() m.Matcher

func HasUserKeyProperty added in v1.1.2

func HasUserKeyProperty(key string) m.Matcher

func HasUserObjectWithKey added in v1.1.2

func HasUserObjectWithKey(key string) m.Matcher
func Header(name string) m.MatcherTransform

Header allows matchers to be applied to a specific named header from an http.Header map. It assumes that there is just one value for that name (i.e. it calls Header.Get()).

func IsAliasEvent added in v1.1.2

func IsAliasEvent() m.Matcher

func IsCustomEvent added in v1.1.2

func IsCustomEvent() m.Matcher

func IsCustomEventForEventKey added in v1.1.2

func IsCustomEventForEventKey(key string) m.Matcher

func IsDebugEvent added in v1.1.2

func IsDebugEvent() m.Matcher

func IsFeatureEvent added in v1.1.2

func IsFeatureEvent() m.Matcher

func IsIdentifyEvent added in v1.1.2

func IsIdentifyEvent() m.Matcher

func IsIdentifyEventForUserKey added in v1.1.2

func IsIdentifyEventForUserKey(key string) m.Matcher

func IsIndexEvent added in v1.1.2

func IsIndexEvent() m.Matcher

func IsIndexEventForUserKey added in v1.1.2

func IsIndexEventForUserKey(key string) m.Matcher

func IsSummaryEvent added in v1.1.2

func IsSummaryEvent() m.Matcher

func IsValidFeatureEventWithConditions added in v1.1.2

func IsValidFeatureEventWithConditions(isPHP, inlineUser bool, user lduser.User, matchers ...m.Matcher) m.Matcher

func IsValidSummaryEventWithFlags added in v1.1.2

func IsValidSummaryEventWithFlags(keyValueMatchers ...m.KeyValueMatcher) m.Matcher

func JSONMatchesUser added in v1.7.0

func JSONMatchesUser(user lduser.User, withOptionalMobileProperties bool) m.Matcher

func JSONPropertyKeysCanOnlyBe added in v1.1.2

func JSONPropertyKeysCanOnlyBe(keys ...string) m.Matcher

func JSONPropertyNullOrAbsent added in v1.1.2

func JSONPropertyNullOrAbsent(name string) m.Matcher

func JSONUserCustomAttributesProperty added in v1.8.0

func JSONUserCustomAttributesProperty(customAttrs map[string]ldvalue.Value, withOptionalMobileProps bool) m.Matcher

func RunSDKTestSuite added in v1.6.0

func RunSDKTestSuite(
	harness *harness.TestHarness,
	filter ldtest.Filter,
	testLogger ldtest.TestLogger,
) ldtest.Results

func SortedStrings added in v1.1.2

func SortedStrings() m.MatcherTransform

func UniqueQueryParameters added in v1.13.0

func UniqueQueryParameters() m.MatcherTransform

UniqueQueryParameters returns a MatcherTransform which parses a string representing a URL's RawQuery field into a map from parameter key to parameter value. If there are multiple values for a key, an error is returned.

func ValueIsPositiveNonZeroInteger added in v1.0.0

func ValueIsPositiveNonZeroInteger() m.Matcher

Types

type BigSegmentStore added in v1.1.0

type BigSegmentStore struct {
	// contains filtered or unexported fields
}

BigSegmentStore is a test fixture that provides callback endpoints for SDK clients to connect to, behaving like a Big Segment store for a simulated database.

func NewBigSegmentStore added in v1.1.0

func NewBigSegmentStore(t *ldtest.T, initialStatus ldreason.BigSegmentsStatus) *BigSegmentStore

NewBigSegmentStore creates a new BigSegmentStore with the specified initial status.

The object's lifecycle is tied to the test scope that created it; it will be automatically closed when this test scope exits. It can be reused by subtests until then. Debug output related to the data source will be attached to this test scope.

func (*BigSegmentStore) Configure added in v1.6.0

func (b *BigSegmentStore) Configure(config *servicedef.SDKConfigParams) error

Configure updates the SDK client configuration for NewSDKClient, causing the SDK to connect to the appropriate base URI for the big segments test fixture.

func (*BigSegmentStore) ExpectMetadataQuery added in v1.1.0

func (b *BigSegmentStore) ExpectMetadataQuery(t *ldtest.T, timeout time.Duration)

ExpectMetadataQuery blocks until the Big Segment store has received a metadata query.

func (*BigSegmentStore) ExpectNoMoreMetadataQueries added in v1.1.0

func (b *BigSegmentStore) ExpectNoMoreMetadataQueries(t *ldtest.T, timeout time.Duration)

ExpectNoMoreMetadataQueries causes a test failure if the Big Segment store receives a metadata query.

func (*BigSegmentStore) GetMembershipQueries added in v1.1.0

func (b *BigSegmentStore) GetMembershipQueries() []string

GetMembershipQueries returns the user hashes of all membership queries that have been received so far.

func (*BigSegmentStore) SetupGetMetadata added in v1.1.0

func (b *BigSegmentStore) SetupGetMetadata(fn func() (ldtime.UnixMillisecondTime, error))

SetupGetMetadata causes the specified function to be called whenever the SDK calls the "get metadata" method on the Big Segment store.

func (*BigSegmentStore) SetupGetUserMembership added in v1.1.0

func (b *BigSegmentStore) SetupGetUserMembership(fn func(userHash string) (map[string]bool, error))

SetupGetUserMembership causes the specified function to be called whenever the SDK calls the "get user membership" method on the Big Segment store.

func (*BigSegmentStore) SetupMemberships added in v1.1.0

func (b *BigSegmentStore) SetupMemberships(t *ldtest.T, memberships map[string]map[string]bool)

SetupMemberships is a shortcut to call SetupGetUserMembership with appropriate logic for providing preconfigured results for each possible user hash. Any user hash whose key does not appear in the map will cause the test to fail.

func (*BigSegmentStore) SetupMetadataForStatus added in v1.1.0

func (b *BigSegmentStore) SetupMetadataForStatus(status ldreason.BigSegmentsStatus)

SetupMetadataForStatus is a shortcut to call SetupGetMetadata with appropriate logic for making the Big Segment store return a current time ("healthy" status), an old time ("stale" status), or an error ("store error" status).

type ClientSideFlagFactoryForValueTypes added in v1.12.0

type ClientSideFlagFactoryForValueTypes struct {
	KeyPrefix       string
	BuilderActions  func(*mockld.ClientSDKFlagWithKey)
	ValueFactory    ValueFactory[servicedef.ValueType]
	Reason          ldreason.EvaluationReason
	StartingVersion int
	// contains filtered or unexported fields
}

func (*ClientSideFlagFactoryForValueTypes) ForType added in v1.12.0

type CommonEvalParameterizedTestRunner added in v1.6.0

type CommonEvalParameterizedTestRunner[SDKDataType mockld.SDKData] struct {
	SDKConfigurers       func(testmodel.EvalTestSuite[SDKDataType]) []SDKConfigurer
	FilterSDKData        func(SDKDataType) SDKDataType
	FilterExpectedReason func(ldreason.EvaluationReason) ldreason.EvaluationReason
}

func (CommonEvalParameterizedTestRunner[SDKDataType]) RunAll added in v1.6.0

func (c CommonEvalParameterizedTestRunner[SDKDataType]) RunAll(t *ldtest.T, dirName string)

type CommonEventTests added in v1.6.0

type CommonEventTests struct {
	// contains filtered or unexported fields
}

CommonEventTests groups together event-related test methods that are shared between server-side and client-side.

func NewCommonEventTests added in v1.7.0

func NewCommonEventTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonEventTests

func (CommonEventTests) AliasEvents added in v1.6.0

func (c CommonEventTests) AliasEvents(t *ldtest.T)

func (CommonEventTests) BufferBehavior added in v1.6.0

func (c CommonEventTests) BufferBehavior(t *ldtest.T)

func (CommonEventTests) CustomEvents added in v1.6.0

func (c CommonEventTests) CustomEvents(t *ldtest.T)

func (CommonEventTests) DisablingEvents added in v1.6.0

func (c CommonEventTests) DisablingEvents(t *ldtest.T)

func (CommonEventTests) EventUsers added in v1.6.0

func (c CommonEventTests) EventUsers(t *ldtest.T)

func (CommonEventTests) IdentifyEvents added in v1.6.0

func (c CommonEventTests) IdentifyEvents(t *ldtest.T)

func (CommonEventTests) RequestMethodAndHeaders added in v1.6.0

func (c CommonEventTests) RequestMethodAndHeaders(t *ldtest.T, credential string, headersMatcher m.Matcher)

func (CommonEventTests) RequestURLPath added in v1.6.0

func (c CommonEventTests) RequestURLPath(t *ldtest.T, pathMatcher m.Matcher)

func (CommonEventTests) UniquePayloadIDs added in v1.6.0

func (c CommonEventTests) UniquePayloadIDs(t *ldtest.T)

type CommonPollingTests added in v1.7.0

type CommonPollingTests struct {
	// contains filtered or unexported fields
}

CommonPollingTests groups together polling-related test methods that are shared between server-side and client-side.

Currently we do not have any tests that actually test *repeated* polling. This is because the SDKs enforce minimum polling intervals that would cause the tests to take a very long time. Therefore, the current tests only cover the behavior of the initial poll request.

func NewCommonPollingTests added in v1.7.0

func NewCommonPollingTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonPollingTests

func (CommonPollingTests) RequestMethodAndHeaders added in v1.7.0

func (c CommonPollingTests) RequestMethodAndHeaders(t *ldtest.T, credential string)

func (CommonPollingTests) RequestURLPath added in v1.7.0

func (c CommonPollingTests) RequestURLPath(t *ldtest.T, pathMatcher func(flagRequestMethod) m.Matcher)

func (CommonPollingTests) RequestUserProperties added in v1.7.0

func (c CommonPollingTests) RequestUserProperties(t *ldtest.T, getPath string)

type CommonStreamingTests added in v1.7.0

type CommonStreamingTests struct {
	// contains filtered or unexported fields
}

CommonStreamingTests groups together streaming-related test methods that are shared between server-side and client-side.

func NewCommonStreamingTests added in v1.7.0

func NewCommonStreamingTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonStreamingTests

func (CommonStreamingTests) RequestMethodAndHeaders added in v1.7.0

func (c CommonStreamingTests) RequestMethodAndHeaders(t *ldtest.T, credential string)

func (CommonStreamingTests) RequestURLPath added in v1.7.0

func (c CommonStreamingTests) RequestURLPath(t *ldtest.T, pathMatcher func(flagRequestMethod) m.Matcher)

func (CommonStreamingTests) RequestUserProperties added in v1.7.0

func (c CommonStreamingTests) RequestUserProperties(t *ldtest.T, getPath string)

func (CommonStreamingTests) Updates added in v1.7.0

func (c CommonStreamingTests) Updates(t *ldtest.T)

type CommonTagsTests added in v1.6.0

type CommonTagsTests struct {
	// contains filtered or unexported fields
}

CommonTagsTests groups together event-related test methods that are shared between server-side and client-side.

func NewCommonTagsTests added in v1.7.0

func NewCommonTagsTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonTagsTests

func (CommonTagsTests) Run added in v1.6.0

func (c CommonTagsTests) Run(t *ldtest.T)

type FlagFactoryForValueTypes

type FlagFactoryForValueTypes struct {
	KeyPrefix       string
	BuilderActions  func(*ldbuilders.FlagBuilder)
	ValueFactory    ValueFactory[servicedef.ValueType]
	Reason          ldreason.EvaluationReason
	StartingVersion int
	// contains filtered or unexported fields
}

func (*FlagFactoryForValueTypes) ForType

type GenericFactory added in v1.12.0

type GenericFactory[ParamT, ResultT any] interface {
	Get(param ParamT) ResultT
}

type MemoizingFactory added in v1.12.0

type MemoizingFactory[ParamT comparable, ResultT any] struct {
	// contains filtered or unexported fields
}

func NewMemoizingClientSideFlagFactory added in v1.12.0

func NewMemoizingClientSideFlagFactory(
	startingVersion int,
	factoryFn func(servicedef.ValueType) mockld.ClientSDKFlagWithKey,
) *MemoizingFactory[servicedef.ValueType, mockld.ClientSDKFlagWithKey]

func NewMemoizingFlagFactory

func NewMemoizingFlagFactory(
	startingVersion int,
	factoryFn func(servicedef.ValueType) ldmodel.FeatureFlag,
) *MemoizingFactory[servicedef.ValueType, ldmodel.FeatureFlag]

func (*MemoizingFactory[P, R]) Get added in v1.12.0

func (f *MemoizingFactory[P, R]) Get(param P) R

type SDKClient

type SDKClient struct {
	// contains filtered or unexported fields
}

SDKClient represents an SDK client instance in the test service which can be controlled by test logic.

func NewSDKClient

func NewSDKClient(t *ldtest.T, configurers ...SDKConfigurer) *SDKClient

NewSDKClient tells the test service to create an SDK client instance.

The first parameter should be the current test scope. Any error in creating the client will cause the test to fail and terminate immediately. Debug output related to the client will be attached to this test scope.

You must always specify at least one SDKConfigurer to customize the SDK configuration, since a default SDK configuration would only connect to LaunchDarkly which is normally not what we want. Test fixture components such as SDKDataSource implement this interface so that they can insert the appropriate base URIs into the configuration, so a common pattern is:

dataSource := NewSDKDataSource(t, ...)
eventSink := NewSDKEventSink(t, ...)
client := NewSDKClient(t, dataSource, eventSink)

Since the client will attempt to connect to its data source and possibly send events as soon as it starts up, the test fixtures must always be created first. You may reuse a previously created data source and event sink that was created in a parent test scope, if you do not need a new one for each client.

The object's lifecycle is tied to the test scope that created it; it will be automatically closed when this test scope exits. It can be reused by subtests until then.

func TryNewSDKClient added in v1.3.0

func TryNewSDKClient(t *ldtest.T, configurers ...SDKConfigurer) (*SDKClient, error)

func (*SDKClient) Close added in v1.3.0

func (c *SDKClient) Close() error

Close tells the test service to shut down the client instance. Normally this happens automatically at the end of a test.

func (*SDKClient) EvaluateAllFlags

EvaluateAllFlags tells the SDK client to evaluate all feature flags. This corresponds to calling the SDK's AllFlags or AllFlagsState method.

Any error from the test service causes the test to terminate immediately.

func (*SDKClient) EvaluateFlag

EvaluateFlag tells the SDK client to evaluate a feature flag. This corresponds to calling one of the SDK's Variation or VariationDetail methods, depending on the parameters.

Any error from the test service causes the test to terminate immediately.

func (*SDKClient) FlushEvents

func (c *SDKClient) FlushEvents(t *ldtest.T)

FlushEvents tells the SDK client to initiate an event flush.

Any error from the test service causes the test to terminate immediately.

func (*SDKClient) GetBigSegmentStoreStatus added in v1.1.0

func (c *SDKClient) GetBigSegmentStoreStatus(t *ldtest.T) servicedef.BigSegmentStoreStatusResponse

GetBigSegmentStoreStatus queries the big segment store status from the SDK client. The test harness will only call this method if the test service has the "big-segments" capability.

func (*SDKClient) GetSecureModeHash added in v1.9.0

func (c *SDKClient) GetSecureModeHash(t *ldtest.T, user lduser.User) string

GetSecureModeHash tells the SDK client to calculate a secure mode hash for a user. The test harness will only call this method if the test service has the "secure-mode-hash" capability.

func (*SDKClient) SendAliasEvent

func (c *SDKClient) SendAliasEvent(t *ldtest.T, params servicedef.AliasEventParams)

SendAliasEvent tells the SDK client to send an alias event.

Any error from the test service causes the test to terminate immediately.

func (*SDKClient) SendCustomEvent

func (c *SDKClient) SendCustomEvent(t *ldtest.T, params servicedef.CustomEventParams)

SendCustomEvent tells the SDK client to send a custom event.

Any error from the test service causes the test to terminate immediately.

func (*SDKClient) SendIdentifyEvent

func (c *SDKClient) SendIdentifyEvent(t *ldtest.T, user lduser.User)

SendIdentifyEvent tells the SDK client to send an identify event.

Any error from the test service causes the test to terminate immediately.

type SDKConfigurer

SDKConfigurer is an interface for objects that can modify the configuration for StartSDKClient. It is implemented by types such as SDKDataSource.

func WithClientSideConfig added in v1.6.0

func WithClientSideConfig(clientSideConfig servicedef.SDKConfigClientSideParams) SDKConfigurer

WithClientSideConfig is used with StartSDKClient to specify a non-default client-side SDK configuration.

func WithConfig

func WithConfig(config servicedef.SDKConfigParams) SDKConfigurer

WithConfig is used with StartSDKClient to specify a non-default SDK configuration. Use this before any other SDKConfigurers or it will overwrite their effects.

func WithCredential added in v1.6.0

func WithCredential(credential string) SDKConfigurer

WithCredential is used with StartSDKClient to set only the credential (SDK key, mobile key, or environment ID).

func WithEventsConfig added in v1.1.2

func WithEventsConfig(eventsConfig servicedef.SDKConfigEventParams) SDKConfigurer

WithEventsConfig is used with StartSDKClient to specify a non-default events configuration.

func WithPollingConfig added in v1.7.0

func WithPollingConfig(pollingConfig servicedef.SDKConfigPollingParams) SDKConfigurer

WithPollingConfig is used with StartSDKClient to specify a non-default polling configuration.

func WithServiceEndpointsConfig added in v1.5.0

func WithServiceEndpointsConfig(endpointsConfig servicedef.SDKConfigServiceEndpointsParams) SDKConfigurer

WithServiceEndpointsConfig is used with StartSDKClient to specify non-default service endpoints. This will only work if the test service has the "service-endpoints" capability.

func WithStreamingConfig added in v1.1.2

func WithStreamingConfig(streamingConfig servicedef.SDKConfigStreamingParams) SDKConfigurer

WithStreamingConfig is used with StartSDKClient to specify a non-default streaming configuration.

type SDKDataSource

type SDKDataSource struct {
	// contains filtered or unexported fields
}

SDKDataSource is a test fixture that provides a callback endpoint for SDK clients to connect to, simulating the LaunchDarkly streaming or polling service.

func NewSDKDataSource

func NewSDKDataSource(t *ldtest.T, data mockld.SDKData, options ...SDKDataSourceOption) *SDKDataSource

NewSDKDataSource creates a new SDKDataSource with the specified initial data set.

It can simulate either the streaming service or the polling service. If you don't explicitly specify DataSourceOptionPolling or DataSourceOptionStreaming, the default depends on what kind of SDK is being tested: server-side and mobile SDKs default to streaming, JS-based client-side SDKs default to polling.

It automatically detects (from the ldtest.T properties) whether we are testing a server-side, mobile, or JS-based client-side SDK, and configures the endpoint behavior as appropriate. The endpoints will enforce that the client only uses supported URL paths and HTTP methods; however, they do not do any validation of credentials (SDK key, mobile key, environment ID) since that would require this component to know more about the overall configuration than it knows. We have specific tests that do verify that the SDKs send appropriate credentials.

The object's lifecycle is tied to the test scope that created it; it will be automatically closed when this test scope exits. It can be reused by subtests until then. Debug output related to the data source will be attached to this test scope.

func NewSDKDataSourceWithoutEndpoint added in v1.0.0

func NewSDKDataSourceWithoutEndpoint(t *ldtest.T, data mockld.SDKData, options ...SDKDataSourceOption) *SDKDataSource

NewSDKDataSourceWithoutEndpoint is the same as NewSDKDataSource, but it does not allocate an endpoint to accept incoming requests. Use this if you want to configure the endpoint separately, for instance if you want it to delegate some requests to the data source but return an error for some other requests.

func (*SDKDataSource) Configure added in v1.6.0

func (d *SDKDataSource) Configure(config *servicedef.SDKConfigParams) error

Configure updates the SDK client configuration for NewSDKClient, causing the SDK to connect to the appropriate base URI for the data source test fixture. This only works if the data source was created along with its own endpoint, with NewSDKDataSource; if it was created as a handler to be used in a separately configured endpoint, you have to set the base URI in the test logic rather than using this shortcut.

func (*SDKDataSource) Endpoint added in v1.0.0

func (d *SDKDataSource) Endpoint() *harness.MockEndpoint

Endpoint returns the low-level object that manages incoming requests.

func (*SDKDataSource) Handler added in v1.0.0

func (d *SDKDataSource) Handler() http.Handler

Handler returns the HTTP handler for the service. Since StreamingService implements http.Handler already, this is the same as Service() but makes the purpose clearer.

func (*SDKDataSource) PollingService added in v1.6.0

func (d *SDKDataSource) PollingService() *mockld.PollingService

PollingService returns the low-level object that manages the polling data, or nil if this is a streaming data source.

func (*SDKDataSource) SetInitialData added in v1.12.1

func (d *SDKDataSource) SetInitialData(data mockld.SDKData)

SetInitialData configures whichever kind of data source this is (streaming or polling) to use the specified data set the next time it receives an SDK connection.

func (*SDKDataSource) StreamingService added in v1.6.0

func (d *SDKDataSource) StreamingService() *mockld.StreamingService

StreamingService returns the low-level object that manages the stream data, or nil if this is a polling data source.

type SDKDataSourceOption added in v1.6.0

type SDKDataSourceOption helpers.ConfigOption[sdkDataSourceConfig]

SDKDataSourceOption is the interface for options to NewSDKDataSource.

func DataSourceOptionPolling added in v1.6.0

func DataSourceOptionPolling() SDKDataSourceOption

DataSourceOptionPolling makes an SDKDataSource simulate the polling service.

func DataSourceOptionStreaming added in v1.6.0

func DataSourceOptionStreaming() SDKDataSourceOption

DataSourceOptionStreaming makes an SDKDataSource simulate the streaming service.

type SDKEventSink

type SDKEventSink struct {
	// contains filtered or unexported fields
}

SDKEventSink is a test fixture that provides a callback endpoint for SDK clients to send event data to, simulating the LaunchDarkly event-recorder service.

func NewSDKEventSink

func NewSDKEventSink(t *ldtest.T) *SDKEventSink

NewSDKEventSink creates a new SDKEventSink.

It automatically detects (from the ldtest.T properties) whether we are testing a server-side, mobile, or JS-based client-side SDK, and configures the endpoint behavior as appropriate. The endpoints will enforce that the client only uses supported URL paths and HTTP methods; however, they do not do any validation of credentials (SDK key, mobile key, environment ID) since that would require this component to know more about the overall configuration than it knows. We have specific tests that do verify that the SDKs send appropriate credentials.

The object's lifecycle is tied to the test scope that created it; it will be automatically closed when this test scope exits. It can be reused by subtests until then. Debug output related to the event sink will be attached to this test scope, and also to any of its subtests that are active when the output is generated.

func (*SDKEventSink) Configure added in v1.6.0

func (e *SDKEventSink) Configure(config *servicedef.SDKConfigParams) error

Configure updates the SDK client configuration for NewSDKClient, causing the SDK to connect to the appropriate base URI for the test fixture.

func (*SDKEventSink) Endpoint added in v1.3.0

func (e *SDKEventSink) Endpoint() *harness.MockEndpoint

Endpoint returns the low-level object that manages incoming requests.

func (*SDKEventSink) ExpectAnalyticsEvents

func (e *SDKEventSink) ExpectAnalyticsEvents(t require.TestingT, timeout time.Duration) mockld.Events

ExpectAnalyticsEvents waits for event data to be posted to the endpoint, and then calls matchers.ItemsInAnyOrder with the specified eventMatchers, verifying that the payload contains one event matching each of the matchers regardless of ordering.

If no new events arrive before the timeout, the test immediately fails and terminates.

The number of events posted must be the same as the number of matchers.

func (*SDKEventSink) ExpectNoAnalyticsEvents

func (e *SDKEventSink) ExpectNoAnalyticsEvents(t require.TestingT, timeout time.Duration)

ExpectNoAnalyticsEvents waits for the specified timeout and fails if any events are posted before then.

func (*SDKEventSink) Service added in v1.1.0

func (e *SDKEventSink) Service() *mockld.EventsService

Service returns the underlying mock events service component, for access to special options.

type SDKTestContext

type SDKTestContext struct {
	// contains filtered or unexported fields
}

type UserFactory

type UserFactory struct {
	// contains filtered or unexported fields
}

func NewUserFactory

func NewUserFactory(prefix string, builderActions ...func(lduser.UserBuilder)) *UserFactory

func (*UserFactory) NextUniqueUser

func (f *UserFactory) NextUniqueUser() lduser.User

func (*UserFactory) NextUniqueUserMaybeAnonymous added in v1.1.0

func (f *UserFactory) NextUniqueUserMaybeAnonymous(shouldBeAnonymous bool) lduser.User

type ValueFactory

type ValueFactory[ParamT any] func(param ParamT) ldvalue.Value

func DefaultValueByTypeFactory

func DefaultValueByTypeFactory() ValueFactory[servicedef.ValueType]

func FlagValueByTypeFactory

func FlagValueByTypeFactory() ValueFactory[servicedef.ValueType]

func SingleValueFactory

func SingleValueFactory(value ldvalue.Value) ValueFactory[servicedef.ValueType]

Jump to

Keyboard shortcuts

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