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 ¶
- func CanonicalizedEventJSON() m.MatcherTransform
- func DoServerSideEvalTests(t *ldtest.T)
- func EvalResponseReason() m.MatcherTransform
- func EvalResponseValue() m.MatcherTransform
- func EvalResponseVariation() m.MatcherTransform
- func EventHasKind(kind string) m.Matcher
- func EventIsCustomEvent(eventKey string, eventUser mockld.EventUser, inlineUser bool, ...) m.Matcher
- func EventIsCustomEventForParams(params servicedef.CustomEventParams, ...) m.Matcher
- func EventIsFeatureEvent(flagKey string, eventUser mockld.EventUser, inlineUser bool, ...) m.Matcher
- func EventIsIdentifyEvent(eventUser mockld.EventUser) m.Matcher
- func EventIsIndexEvent(eventUser mockld.EventUser) m.Matcher
- func RunParameterizedServerSideEvalTests(t *ldtest.T)
- func RunServerSideTestSuite(harness *harness.TestHarness, filter ldtest.Filter, ...) ldtest.Results
- type FlagFactory
- type FlagFactoryForValueTypes
- type MemoizingFlagFactory
- type SDKClient
- 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) SendAliasEvent(t *ldtest.T, params servicedef.AliasEventParams)
- func (c *SDKClient) SendCustomEvent(t *ldtest.T, params servicedef.CustomEventParams)
- func (c *SDKClient) SendIdentifyEvent(t *ldtest.T, user lduser.User)
- type SDKConfigurer
- type SDKDataSource
- type SDKEventSink
- type SDKTestContext
- type UserFactory
- type ValueFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalizedEventJSON ¶
func CanonicalizedEventJSON() m.MatcherTransform
func DoServerSideEvalTests ¶
func EvalResponseReason ¶
func EvalResponseReason() m.MatcherTransform
func EvalResponseValue ¶
func EvalResponseValue() m.MatcherTransform
func EvalResponseVariation ¶
func EvalResponseVariation() m.MatcherTransform
func EventHasKind ¶
func EventIsCustomEvent ¶
func EventIsCustomEventForParams ¶
func EventIsCustomEventForParams( params servicedef.CustomEventParams, eventConfig servicedef.SDKConfigEventParams, ) m.Matcher
func EventIsFeatureEvent ¶
func RunServerSideTestSuite ¶
func RunServerSideTestSuite( harness *harness.TestHarness, filter ldtest.Filter, testLogger ldtest.TestLogger, ) ldtest.Results
Types ¶
type FlagFactory ¶
type FlagFactory interface {
MakeFlag(param interface{}) ldmodel.FeatureFlag
}
func NewMemoizingFlagFactory ¶
func NewMemoizingFlagFactory(startingVersion int, factoryFn func(interface{}) ldmodel.FeatureFlag) FlagFactory
type FlagFactoryForValueTypes ¶
type FlagFactoryForValueTypes struct { KeyPrefix string BuilderActions func(*ldbuilders.FlagBuilder) ValueFactory ValueFactory Reason ldreason.EvaluationReason StartingVersion int // contains filtered or unexported fields }
func (*FlagFactoryForValueTypes) ForType ¶
func (f *FlagFactoryForValueTypes) ForType(valueType servicedef.ValueType) ldmodel.FeatureFlag
type MemoizingFlagFactory ¶
type MemoizingFlagFactory struct {
// contains filtered or unexported fields
}
func (*MemoizingFlagFactory) MakeFlag ¶
func (f *MemoizingFlagFactory) MakeFlag(param interface{}) ldmodel.FeatureFlag
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 (*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) 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.
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.
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 (*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 test fixture.
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) ExpectAnalyticsEvents ¶
func (e *SDKEventSink) ExpectAnalyticsEvents(t matchers.RequireT, 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.
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
type ValueFactory ¶
func DefaultValueByTypeFactory ¶
func DefaultValueByTypeFactory() ValueFactory
func FlagValueByTypeFactory ¶
func FlagValueByTypeFactory() ValueFactory
func SingleValueFactory ¶
func SingleValueFactory(value ldvalue.Value) ValueFactory
Source Files ¶
- custom_matchers.go
- package_info.go
- server_side_eval.go
- server_side_events_alias.go
- server_side_events_custom.go
- server_side_events_eval.go
- server_side_events_identify.go
- server_side_events_users.go
- testapi_context.go
- testapi_sdk_client.go
- testapi_sdk_data.go
- testapi_sdk_events.go
- testdata_factories.go
- testsuite_server_side.go