sdktests

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 20 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 CanonicalizedEventJSON

func CanonicalizedEventJSON() m.MatcherTransform

func DoServerSideEvalTests

func DoServerSideEvalTests(t *ldtest.T)

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 EventIsCustomEvent

func EventIsCustomEvent(
	eventKey string,
	eventUser mockld.EventUser,
	inlineUser bool,
	data ldvalue.Value,
	metricValue *float64,
) m.Matcher

func EventIsCustomEventForParams

func EventIsCustomEventForParams(
	params servicedef.CustomEventParams,
	eventConfig servicedef.SDKConfigEventParams,
) m.Matcher

func EventIsFeatureEvent

func EventIsFeatureEvent(
	flagKey string,
	eventUser mockld.EventUser,
	inlineUser bool,
	flagVersion ldvalue.OptionalInt,
	value ldvalue.Value,
	variation ldvalue.OptionalInt,
	reason ldreason.EvaluationReason,
	defaultValue ldvalue.Value,
) m.Matcher

func EventIsIdentifyEvent

func EventIsIdentifyEvent(eventUser mockld.EventUser) m.Matcher

func EventIsIndexEvent

func EventIsIndexEvent(eventUser mockld.EventUser) m.Matcher

func RunParameterizedServerSideEvalTests

func RunParameterizedServerSideEvalTests(t *ldtest.T)

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

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

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

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

type ValueFactory func(param interface{}) ldvalue.Value

func DefaultValueByTypeFactory

func DefaultValueByTypeFactory() ValueFactory

func FlagValueByTypeFactory

func FlagValueByTypeFactory() ValueFactory

func SingleValueFactory

func SingleValueFactory(value ldvalue.Value) ValueFactory

Jump to

Keyboard shortcuts

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