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
data: test data file schemas and loader
Index ¶
- func Base64DecodedData() m.MatcherTransform
- func EqualReason(reason ldreason.EvaluationReason) m.Matcher
- func EvalAllFlagsStateMap() m.MatcherTransform
- func EvalAllFlagsValueForKeyShouldEqual(key string, value ldvalue.Value) m.Matcher
- func EvalResponseReason() m.MatcherTransform
- func EvalResponseValue() m.MatcherTransform
- func EvalResponseVariation() m.MatcherTransform
- func EventHasKind(kind string) m.Matcher
- func HasAnyCreationDate() m.Matcher
- func HasAuthorizationHeader(authKey string) m.Matcher
- func HasContextKeys(context ldcontext.Context) m.Matcher
- func HasContextObjectWithKey(key string) m.Matcher
- func HasContextObjectWithMatchingKeys(context ldcontext.Context) m.Matcher
- func HasNoAuthorizationHeader() m.Matcher
- func HasNoContextObject() m.Matcher
- func Header(name string) m.MatcherTransform
- func IsCustomEvent() m.Matcher
- func IsCustomEventForEventKey(key string) m.Matcher
- func IsDebugEvent() m.Matcher
- func IsFeatureEvent() m.Matcher
- func IsIdentifyEvent() m.Matcher
- func IsIdentifyEventForContext(context ldcontext.Context) m.Matcher
- func IsIndexEvent() m.Matcher
- func IsIndexEventForContext(context ldcontext.Context) m.Matcher
- func IsMigrationOpEvent() m.Matcher
- func IsSummaryEvent() m.Matcher
- func IsValidFeatureEventWithConditions(t *ldtest.T, isPHP bool, context ldcontext.Context, matchers ...m.Matcher) m.Matcher
- func IsValidMigrationOpEventWithConditions(context ldcontext.Context, matchers ...m.Matcher) m.Matcher
- func IsValidSummaryEventWithFlags(keyValueMatchers ...m.KeyValueMatcher) m.Matcher
- func JSONMatchesContext(context ldcontext.Context) m.Matcher
- func JSONMatchesEventContext(context ldcontext.Context, redactedShouldBe map[string][]string) m.Matcher
- func JSONPropertyKeysCanOnlyBe(keys ...string) m.Matcher
- func JSONPropertyNullOrAbsent(name string) m.Matcher
- func JSONPropertyNullOrAbsentOrEqualTo(name string, emptyValue interface{}) m.Matcher
- func RedactedAttributesAre(attrStrings ...string) m.Matcher
- func RunSDKTestSuite(harness *harness.TestHarness, filter ldtest.Filter, ...) ldtest.Results
- func SortedStrings() m.MatcherTransform
- func UniqueQueryParameters() m.MatcherTransform
- func ValueIsPositiveNonZeroInteger() m.Matcher
- type BigSegmentStore
- func (b *BigSegmentStore) Configure(config *servicedef.SDKConfigParams) error
- func (b *BigSegmentStore) ExpectMetadataQuery(t *ldtest.T, timeout time.Duration)
- func (b *BigSegmentStore) ExpectNoMoreMetadataQueries(t *ldtest.T, timeout time.Duration)
- func (b *BigSegmentStore) GetMembershipQueries() []string
- func (b *BigSegmentStore) SetupGetMembership(fn func(contextHash string) (map[string]bool, error))
- func (b *BigSegmentStore) SetupGetMetadata(fn func() (ldtime.UnixMillisecondTime, error))
- func (b *BigSegmentStore) SetupMemberships(t *ldtest.T, memberships map[string]map[string]bool)
- func (b *BigSegmentStore) SetupMetadataForStatus(status ldreason.BigSegmentsStatus)
- type CommonEvalParameterizedTestRunner
- type CommonEventTests
- func (c CommonEventTests) BufferBehavior(t *ldtest.T)
- func (c CommonEventTests) CustomEvents(t *ldtest.T)
- func (c CommonEventTests) DisablingEvents(t *ldtest.T)
- func (c CommonEventTests) EventContexts(t *ldtest.T)
- func (c CommonEventTests) IdentifyEvents(t *ldtest.T)
- func (c CommonEventTests) RequestMethodAndHeaders(t *ldtest.T, credential string, headersMatcher m.Matcher)
- func (c CommonEventTests) RequestURLPath(t *ldtest.T, pathMatcher m.Matcher)
- func (c CommonEventTests) UniquePayloadIDs(t *ldtest.T)
- type CommonPollingTests
- func (c CommonPollingTests) InitialRequestIncludesCorrectEtag(t *ldtest.T)
- func (c CommonPollingTests) LargePayloads(t *ldtest.T)
- func (c CommonPollingTests) RequestContextProperties(t *ldtest.T, getPath string)
- func (c CommonPollingTests) RequestMethodAndHeaders(t *ldtest.T, credential string)
- func (c CommonPollingTests) RequestURLPath(t *ldtest.T, pathMatcher func(flagRequestMethod) m.Matcher)
- type CommonStreamingTests
- func (c CommonStreamingTests) RequestContextProperties(t *ldtest.T, getPath string)
- func (c CommonStreamingTests) RequestMethodAndHeaders(t *ldtest.T, credential string)
- func (c CommonStreamingTests) RequestURLPath(t *ldtest.T, pathMatcher func(flagRequestMethod) m.Matcher)
- func (c CommonStreamingTests) Updates(t *ldtest.T)
- type CommonTagsTests
- type HookInstance
- type Hooks
- type SDKClient
- func (c *SDKClient) Close() error
- func (c *SDKClient) ContextBuild(t *ldtest.T, params servicedef.ContextBuildParams) servicedef.ContextBuildResponse
- func (c *SDKClient) ContextComparison(t *ldtest.T, params servicedef.ContextComparisonPairParams) servicedef.ContextComparisonResponse
- func (c *SDKClient) ContextConvert(t *ldtest.T, params servicedef.ContextConvertParams) servicedef.ContextBuildResponse
- func (c *SDKClient) EvaluateAllFlags(t *ldtest.T, params servicedef.EvaluateAllFlagsParams) servicedef.EvaluateAllFlagsResponse
- func (c *SDKClient) EvaluateFlag(t *ldtest.T, params servicedef.EvaluateFlagParams) servicedef.EvaluateFlagResponse
- func (c *SDKClient) FlushEvents(t *ldtest.T)
- func (c *SDKClient) GetBigSegmentStoreStatus(t *ldtest.T) servicedef.BigSegmentStoreStatusResponse
- func (c *SDKClient) GetSecureModeHash(t *ldtest.T, context ldcontext.Context) string
- func (c *SDKClient) GetSecureModeHashWithOldUser(t *ldtest.T, user json.RawMessage) string
- func (c *SDKClient) MigrationOperation(t *ldtest.T, params servicedef.MigrationOperationParams) servicedef.MigrationOperationResponse
- func (c *SDKClient) MigrationVariation(t *ldtest.T, params servicedef.MigrationVariationParams) servicedef.MigrationVariationResponse
- func (c *SDKClient) SendCustomEvent(t *ldtest.T, params servicedef.CustomEventParams)
- func (c *SDKClient) SendIdentifyEvent(t *ldtest.T, context ldcontext.Context)
- func (c *SDKClient) SendIdentifyEventWithOldUser(t *ldtest.T, user json.RawMessage)
- type SDKConfigurer
- func WithClientSideConfig(clientSideConfig servicedef.SDKConfigClientSideParams) SDKConfigurer
- func WithClientSideInitialContext(context ldcontext.Context) SDKConfigurer
- func WithConfig(config servicedef.SDKConfigParams) SDKConfigurer
- func WithCredential(credential string) SDKConfigurer
- func WithEventsConfig(eventsConfig servicedef.SDKConfigEventParams) SDKConfigurer
- func WithPollingConfig(pollingConfig servicedef.SDKConfigPollingParams) SDKConfigurer
- func WithServiceEndpointsConfig(endpointsConfig servicedef.SDKConfigServiceEndpointsParams) SDKConfigurer
- func WithStreamingConfig(streamingConfig servicedef.SDKConfigStreamingParams) SDKConfigurer
- type SDKDataSource
- func (d *SDKDataSource) Configure(config *servicedef.SDKConfigParams) error
- func (d *SDKDataSource) Endpoint() *harness.MockEndpoint
- func (d *SDKDataSource) Handler() http.Handler
- func (d *SDKDataSource) PollingService() *mockld.PollingService
- func (d *SDKDataSource) SetInitialData(data mockld.SDKData)
- func (d *SDKDataSource) StreamingService() *mockld.StreamingService
- type SDKDataSourceOption
- type SDKEventSink
- func (e *SDKEventSink) Configure(config *servicedef.SDKConfigParams) error
- func (e *SDKEventSink) Endpoint() *harness.MockEndpoint
- func (e *SDKEventSink) ExpectAnalyticsEvents(t require.TestingT, timeout time.Duration) mockld.Events
- func (e *SDKEventSink) ExpectNoAnalyticsEvents(t require.TestingT, timeout time.Duration)
- func (e *SDKEventSink) Service() *mockld.EventsService
- type SDKTestContext
- type VariationParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64DecodedData ¶
func Base64DecodedData() m.MatcherTransform
func EqualReason ¶
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 ¶
func EvalAllFlagsStateMap() m.MatcherTransform
func EvalResponseReason ¶
func EvalResponseReason() m.MatcherTransform
func EvalResponseValue ¶
func EvalResponseValue() m.MatcherTransform
func EvalResponseVariation ¶
func EvalResponseVariation() m.MatcherTransform
func EventHasKind ¶
func HasAnyCreationDate ¶
func HasAuthorizationHeader ¶
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 HasContextObjectWithKey ¶
func HasNoContextObject ¶
func Header ¶
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 IsCustomEvent ¶
func IsDebugEvent ¶
func IsFeatureEvent ¶
func IsIdentifyEvent ¶
func IsIndexEvent ¶
func IsMigrationOpEvent ¶ added in v2.2.0
func IsSummaryEvent ¶
func IsValidMigrationOpEventWithConditions ¶ added in v2.2.0
func IsValidSummaryEventWithFlags ¶
func IsValidSummaryEventWithFlags(keyValueMatchers ...m.KeyValueMatcher) m.Matcher
func JSONMatchesContext ¶
JSONMatchesContext builds a Matcher to verify that the input JSON is a valid representation of the specified context. This is using the regular context schema (i.e. what would be sent to evaluation endpoints), not the event schema.
The matcher should be tolerant of all allowable variants: for instance, it is legal to include `"anonymous": false` in the representation rather than omitting anonymous.
func JSONMatchesEventContext ¶
func JSONMatchesEventContext(context ldcontext.Context, redactedShouldBe map[string][]string) m.Matcher
JSONMatchesEventContext builds a Matcher to verify that the input JSON is a valid representation of the specified context within event data. The context should represent the attributes *after* any private attribute redaction; redactedShouldBe specifies what we expect to see in redactedAttributes.
The matcher should be tolerant of all allowable variants: for instance, it is legal to include `"anonymous": false` in the representation rather than omitting anonymous, and attribute names that appear in redactedAttributes could either use the literal syntax or the slash syntax.
func RedactedAttributesAre ¶
RedactedAttributesAre is a matcher for the value of an event context's redactedAttributes property, verifying that it has the specified attribute names/references and no others. This is not just a plain slice match, because 1. they can be in any order and 2. for simple attribute names, the SDK is allowed to send either "name" or "/name" (with any slashes or tildes escaped in the latter case).
func RunSDKTestSuite ¶
func RunSDKTestSuite( harness *harness.TestHarness, filter ldtest.Filter, testLogger ldtest.TestLogger, ) ldtest.Results
func SortedStrings ¶
func SortedStrings() m.MatcherTransform
func UniqueQueryParameters ¶
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.
Types ¶
type BigSegmentStore ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (b *BigSegmentStore) GetMembershipQueries() []string
GetMembershipQueries returns the context hashes of all membership queries that have been received so far.
func (*BigSegmentStore) SetupGetMembership ¶
func (b *BigSegmentStore) SetupGetMembership(fn func(contextHash string) (map[string]bool, error))
SetupGetMembership causes the specified function to be called whenever the SDK calls the "get membership" method on the Big Segment store.
func (*BigSegmentStore) SetupGetMetadata ¶
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) SetupMemberships ¶
SetupMemberships is a shortcut to call SetupGetMembership with appropriate logic for providing preconfigured results for each possible context hash. Any context hash whose key does not appear in the map will cause the test to fail.
func (*BigSegmentStore) SetupMetadataForStatus ¶
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 CommonEvalParameterizedTestRunner ¶
type CommonEvalParameterizedTestRunner[SDKDataType mockld.SDKData] struct { SDKConfigurers func(testmodel.EvalTestSuite[SDKDataType]) []SDKConfigurer FilterSDKData func(SDKDataType) SDKDataType FilterExpectedReason func(ldreason.EvaluationReason) ldreason.EvaluationReason }
type CommonEventTests ¶
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 ¶
func NewCommonEventTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonEventTests
func (CommonEventTests) BufferBehavior ¶
func (c CommonEventTests) BufferBehavior(t *ldtest.T)
func (CommonEventTests) CustomEvents ¶
func (c CommonEventTests) CustomEvents(t *ldtest.T)
func (CommonEventTests) DisablingEvents ¶
func (c CommonEventTests) DisablingEvents(t *ldtest.T)
func (CommonEventTests) EventContexts ¶
func (c CommonEventTests) EventContexts(t *ldtest.T)
func (CommonEventTests) IdentifyEvents ¶
func (c CommonEventTests) IdentifyEvents(t *ldtest.T)
func (CommonEventTests) RequestMethodAndHeaders ¶
func (CommonEventTests) RequestURLPath ¶
func (c CommonEventTests) RequestURLPath(t *ldtest.T, pathMatcher m.Matcher)
func (CommonEventTests) UniquePayloadIDs ¶
func (c CommonEventTests) UniquePayloadIDs(t *ldtest.T)
type CommonPollingTests ¶
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 ¶
func NewCommonPollingTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonPollingTests
func (CommonPollingTests) InitialRequestIncludesCorrectEtag ¶ added in v2.4.0
func (c CommonPollingTests) InitialRequestIncludesCorrectEtag(t *ldtest.T)
func (CommonPollingTests) LargePayloads ¶ added in v2.1.0
func (c CommonPollingTests) LargePayloads(t *ldtest.T)
func (CommonPollingTests) RequestContextProperties ¶
func (c CommonPollingTests) RequestContextProperties(t *ldtest.T, getPath string)
func (CommonPollingTests) RequestMethodAndHeaders ¶
func (c CommonPollingTests) RequestMethodAndHeaders(t *ldtest.T, credential string)
func (CommonPollingTests) RequestURLPath ¶
func (c CommonPollingTests) RequestURLPath(t *ldtest.T, pathMatcher func(flagRequestMethod) m.Matcher)
type CommonStreamingTests ¶
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 ¶
func NewCommonStreamingTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonStreamingTests
func (CommonStreamingTests) RequestContextProperties ¶
func (c CommonStreamingTests) RequestContextProperties(t *ldtest.T, getPath string)
func (CommonStreamingTests) RequestMethodAndHeaders ¶
func (c CommonStreamingTests) RequestMethodAndHeaders(t *ldtest.T, credential string)
func (CommonStreamingTests) RequestURLPath ¶
func (c CommonStreamingTests) RequestURLPath(t *ldtest.T, pathMatcher func(flagRequestMethod) m.Matcher)
func (CommonStreamingTests) Updates ¶
func (c CommonStreamingTests) Updates(t *ldtest.T)
type CommonTagsTests ¶
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 ¶
func NewCommonTagsTests(t *ldtest.T, testName string, baseSDKConfigurers ...SDKConfigurer) CommonTagsTests
func (CommonTagsTests) Run ¶
func (c CommonTagsTests) Run(t *ldtest.T)
type HookInstance ¶ added in v2.9.0
type HookInstance struct {
// contains filtered or unexported fields
}
type Hooks ¶ added in v2.9.0
type Hooks struct {
// contains filtered or unexported fields
}
func NewHooks ¶ added in v2.9.0
func NewHooks( testHarness *harness.TestHarness, logger framework.Logger, instances []string, data map[servicedef.HookStage]servicedef.SDKConfigEvaluationHookData, errors map[servicedef.HookStage]o.Maybe[string], ) *Hooks
func (*Hooks) Configure ¶ added in v2.9.0
func (h *Hooks) Configure(config *servicedef.SDKConfigParams) error
func (*Hooks) ExpectAtLeastOneCallForEachHook ¶ added in v2.10.0
func (h *Hooks) ExpectAtLeastOneCallForEachHook(t *ldtest.T, hookNames []string) []servicedef.HookExecutionPayload
ExpectAtLeastOneCallForEachHook waits for a single call from N hooks. If there are fewer calls recorded, the test will fail. However, this helper cannot detect if there were more calls waiting to be recorded.
func (*Hooks) ExpectCall ¶ added in v2.9.0
func (h *Hooks) ExpectCall(t *ldtest.T, hookName string, matcher func(payload servicedef.HookExecutionPayload) bool)
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 ¶
func TryNewSDKClient(t *ldtest.T, configurers ...SDKConfigurer) (*SDKClient, error)
func (*SDKClient) Close ¶
Close tells the test service to shut down the client instance. Normally this happens automatically at the end of a test.
func (*SDKClient) ContextBuild ¶
func (c *SDKClient) ContextBuild(t *ldtest.T, params servicedef.ContextBuildParams) servicedef.ContextBuildResponse
ContextBuild tells the test service to use the SDK's context builder to build a context and return it as JSON.
func (*SDKClient) ContextComparison ¶ added in v2.3.0
func (c *SDKClient) ContextComparison(t *ldtest.T, params servicedef.ContextComparisonPairParams, ) servicedef.ContextComparisonResponse
ContextComparison tells the test service to use the SDK's context builder to build two different contexts and compare them for equality.
func (*SDKClient) ContextConvert ¶
func (c *SDKClient) ContextConvert( t *ldtest.T, params servicedef.ContextConvertParams, ) servicedef.ContextBuildResponse
ContextConvert tells the test service to use the SDK's JSON converters to unmarshal and remarshal a context.
func (*SDKClient) EvaluateAllFlags ¶
func (c *SDKClient) EvaluateAllFlags( t *ldtest.T, params servicedef.EvaluateAllFlagsParams, ) servicedef.EvaluateAllFlagsResponse
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 ¶
func (c *SDKClient) EvaluateFlag(t *ldtest.T, params servicedef.EvaluateFlagParams) servicedef.EvaluateFlagResponse
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 ¶
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 ¶
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 ¶
GetSecureModeHash tells the SDK client to calculate a secure mode hash for a context. The test harness will only call this method if the test service has the "secure-mode-hash" capability.
func (*SDKClient) GetSecureModeHashWithOldUser ¶
GetSecureModeHashWithOldUser is equivalent to GetSecureModeHash, but with old-style user JSON data.
func (*SDKClient) MigrationOperation ¶ added in v2.2.0
func (c *SDKClient) MigrationOperation( t *ldtest.T, params servicedef.MigrationOperationParams, ) servicedef.MigrationOperationResponse
MigrationOperation tells the SDK client to evaluate a feature flag representing a migration. This corresponds to calling the SDK's MigrationOperation method.
Any error from the test service causes the test to terminate immediately.
func (*SDKClient) MigrationVariation ¶ added in v2.2.0
func (c *SDKClient) MigrationVariation( t *ldtest.T, params servicedef.MigrationVariationParams, ) servicedef.MigrationVariationResponse
MigrationVariation tells the SDK client to evaluate a feature flag representing a migration. This corresponds to calling the SDK's MigrationVariation method.
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 ¶
SendIdentifyEvent tells the SDK client to send an identify event.
Any error from the test service causes the test to terminate immediately.
func (*SDKClient) SendIdentifyEventWithOldUser ¶
func (c *SDKClient) SendIdentifyEventWithOldUser(t *ldtest.T, user json.RawMessage)
SendIdentifyEventWithOldUser is equivalent to SendIdentifyEvent, but with old-style user data.
type SDKConfigurer ¶
type SDKConfigurer helpers.ConfigOption[servicedef.SDKConfigParams]
SDKConfigurer is an interface for objects that can modify the configuration for StartSDKClient. It is implemented by types such as SDKDataSource.
func WithClientSideConfig ¶
func WithClientSideConfig(clientSideConfig servicedef.SDKConfigClientSideParams) SDKConfigurer
WithClientSideConfig is used with StartSDKClient to specify a non-default client-side SDK configuration.
func WithClientSideInitialContext ¶
func WithClientSideInitialContext(context ldcontext.Context) SDKConfigurer
WithClientSideInitialContext is used with StartSDKClient to set the initial context for a client-side SDK.
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 ¶
func WithCredential(credential string) SDKConfigurer
WithCredential is used with StartSDKClient to set only the credential (SDK key, mobile key, or environment ID).
func WithEventsConfig ¶
func WithEventsConfig(eventsConfig servicedef.SDKConfigEventParams) SDKConfigurer
WithEventsConfig is used with StartSDKClient to specify a non-default events configuration.
func WithPollingConfig ¶
func WithPollingConfig(pollingConfig servicedef.SDKConfigPollingParams) SDKConfigurer
WithPollingConfig is used with StartSDKClient to specify a non-default polling configuration.
func WithServiceEndpointsConfig ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (d *SDKDataSource) Endpoint() *harness.MockEndpoint
Endpoint returns the low-level object that manages incoming requests.
func (*SDKDataSource) Handler ¶
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 ¶
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 ¶
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 ¶
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 ¶
type SDKDataSourceOption helpers.ConfigOption[sdkDataSourceConfig]
SDKDataSourceOption is the interface for options to NewSDKDataSource.
func DataSourceOptionPolling ¶
func DataSourceOptionPolling() SDKDataSourceOption
DataSourceOptionPolling makes an SDKDataSource simulate the polling service.
func DataSourceOptionStreaming ¶
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 ¶
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 ¶
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 ¶
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 VariationParameters ¶ added in v2.9.0
type VariationParameters struct {
// contains filtered or unexported fields
}
Source Files ¶
- client_side_auto_env_attributes.go
- client_side_client_independence.go
- client_side_eval.go
- client_side_events_all.go
- client_side_events_eval.go
- client_side_events_experimentation.go
- client_side_events_summary.go
- client_side_poll_all.go
- client_side_stream_all.go
- client_side_tags.go
- common_tests_base.go
- common_tests_eval.go
- common_tests_events_base.go
- common_tests_events_buffer.go
- common_tests_events_contexts.go
- common_tests_events_custom.go
- common_tests_events_disable.go
- common_tests_events_identify.go
- common_tests_events_request.go
- common_tests_hooks.go
- common_tests_poll_base.go
- common_tests_poll_request.go
- common_tests_stream_base.go
- common_tests_stream_request.go
- common_tests_stream_updates.go
- common_tests_tags.go
- constants.go
- custom_matchers_contexts.go
- custom_matchers_events.go
- custom_matchers_general.go
- helpers.go
- package_info.go
- php_eval.go
- php_events_all.go
- php_events_eval.go
- sdk_context_type.go
- server_side_big_segments.go
- server_side_eval.go
- server_side_eval_all_flags.go
- server_side_eval_bucketing.go
- server_side_events_all.go
- server_side_events_eval.go
- server_side_events_experimentation.go
- server_side_events_index.go
- server_side_events_summary.go
- server_side_migrations.go
- server_side_poll_all.go
- server_side_secure_mode_hash.go
- server_side_service_endpoints.go
- server_side_stream_all.go
- server_side_stream_retry.go
- server_side_stream_validation.go
- server_side_tags.go
- testapi_context.go
- testapi_hooks.go
- testapi_sdk_big_segments.go
- testapi_sdk_client.go
- testapi_sdk_data.go
- testapi_sdk_events.go
- testsuite_entry_point.go