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 AllImportantServerSideCapabilities() framework.Capabilities
- func DoServerSideEvalTests(t *ldtest.T)
- 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 HasContextKeys(context ldcontext.Context) m.Matcher
- func HasContextObjectWithKey(key string) m.Matcher
- func HasContextObjectWithMatchingKeys(context ldcontext.Context) m.Matcher
- func HasNoContextObject() m.Matcher
- 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 IsSummaryEvent() m.Matcher
- func IsValidFeatureEventWithConditions(matchers ...m.Matcher) m.Matcher
- func IsValidSummaryEventWithFlags(keyValueMatchers ...m.KeyValueMatcher) m.Matcher
- func JSONPropertyKeysCanOnlyBe(keys ...string) m.Matcher
- func JSONPropertyNullOrAbsent(name string) m.Matcher
- func RedactedAttributesAre(attrStrings ...string) m.Matcher
- func RunParameterizedServerSideClientNotReadyEvalTests(t *ldtest.T)
- func RunParameterizedServerSideEvalTests(t *ldtest.T)
- func RunServerSideEvalAllFlagsTests(t *ldtest.T)
- func RunServerSideTestSuite(harness *harness.TestHarness, filter ldtest.Filter, ...) ldtest.Results
- func SortedStrings() m.MatcherTransform
- func ValueIsPositiveNonZeroInteger() m.Matcher
- type BigSegmentStore
- func (b *BigSegmentStore) ApplyConfiguration(config *servicedef.SDKConfigParams)
- 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 SDKClient
- func (c *SDKClient) Close() error
- func (c *SDKClient) ContextBuild(t *ldtest.T, params servicedef.ContextBuildParams) servicedef.ContextBuildResponse
- 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) SendCustomEvent(t *ldtest.T, params servicedef.CustomEventParams)
- func (c *SDKClient) SendIdentifyEvent(t *ldtest.T, context ldcontext.Context)
- type SDKConfigurer
- type SDKDataSource
- type SDKEventSink
- func (e *SDKEventSink) ApplyConfiguration(config *servicedef.SDKConfigParams)
- 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllImportantServerSideCapabilities ¶
func AllImportantServerSideCapabilities() framework.Capabilities
func DoServerSideEvalTests ¶
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 HasContextObjectWithKey ¶
func HasNoContextObject ¶
func IsCustomEvent ¶
func IsDebugEvent ¶
func IsFeatureEvent ¶
func IsIdentifyEvent ¶
func IsIndexEvent ¶
func IsSummaryEvent ¶
func IsValidSummaryEventWithFlags ¶
func IsValidSummaryEventWithFlags(keyValueMatchers ...m.KeyValueMatcher) m.Matcher
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 RunServerSideTestSuite ¶
func RunServerSideTestSuite( harness *harness.TestHarness, filter ldtest.Filter, testLogger ldtest.TestLogger, ) ldtest.Results
func SortedStrings ¶
func SortedStrings() m.MatcherTransform
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) ApplyConfiguration ¶
func (b *BigSegmentStore) ApplyConfiguration(config *servicedef.SDKConfigParams)
ApplyConfiguration 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 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, configurer SDKConfigurer, moreConfigurers ...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, configurer SDKConfigurer, moreConfigurers ...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) 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) 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.
type SDKConfigurer ¶
type SDKConfigurer interface {
ApplyConfiguration(*servicedef.SDKConfigParams)
}
SDKConfigurer is an interface for objects that can modify the configuration for StartSDKClient. It is implemented by types such as SDKDataSource.
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 WithEventsConfig ¶
func WithEventsConfig(eventsConfig servicedef.SDKConfigEventParams) SDKConfigurer
WithEventsConfig is used with StartSDKClient to specify a non-default events configuration.
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) *SDKDataSource
NewSDKDataSource creates a new SDKDataSource with the specified initial data set.
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) *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) ApplyConfiguration ¶
func (d *SDKDataSource) ApplyConfiguration(config *servicedef.SDKConfigParams)
ApplyConfiguration 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 stream. Since StreamingService implements http.Handler already, this is the same as Service() but makes the purpose clearer.
func (*SDKDataSource) Service ¶
func (d *SDKDataSource) Service() *mockld.StreamingService
Service returns the low-level object that manages the stream data.
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.
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.
func (*SDKEventSink) ApplyConfiguration ¶
func (e *SDKEventSink) ApplyConfiguration(config *servicedef.SDKConfigParams)
ApplyConfiguration 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
}
Source Files ¶
- constants.go
- custom_matchers_events.go
- custom_matchers_general.go
- helpers.go
- package_info.go
- sdk_context_type.go
- server_side_big_segments.go
- server_side_data_store_updates.go
- server_side_eval.go
- server_side_eval_all_flags.go
- server_side_events_buffer.go
- server_side_events_contexts.go
- server_side_events_custom.go
- server_side_events_eval.go
- server_side_events_experimentation.go
- server_side_events_identify.go
- server_side_events_index.go
- server_side_events_summary.go
- server_side_stream_request.go
- server_side_stream_retry.go
- server_side_stream_validation.go
- server_side_tags.go
- testapi_context.go
- testapi_sdk_big_segments.go
- testapi_sdk_client.go
- testapi_sdk_data.go
- testapi_sdk_events.go
- testsuite_server_side.go