sdktests

package
v2.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 27 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

data: test data file schemas and loader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllImportantServerSideCapabilities

func AllImportantServerSideCapabilities() framework.Capabilities

func DoServerSideEvalTests

func DoServerSideEvalTests(t *ldtest.T)

func EvalAllFlagsStateMap

func EvalAllFlagsStateMap() m.MatcherTransform

func EvalAllFlagsValueForKeyShouldEqual

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

func HasAnyCreationDate() m.Matcher

func HasContextKeys

func HasContextKeys(context ldcontext.Context) m.Matcher

func HasContextObjectWithKey

func HasContextObjectWithKey(key string) m.Matcher

func HasContextObjectWithMatchingKeys

func HasContextObjectWithMatchingKeys(context ldcontext.Context) m.Matcher

func HasNoContextObject

func HasNoContextObject() m.Matcher

func IsCustomEvent

func IsCustomEvent() m.Matcher

func IsCustomEventForEventKey

func IsCustomEventForEventKey(key string) m.Matcher

func IsDebugEvent

func IsDebugEvent() m.Matcher

func IsFeatureEvent

func IsFeatureEvent() m.Matcher

func IsIdentifyEvent

func IsIdentifyEvent() m.Matcher

func IsIdentifyEventForContext

func IsIdentifyEventForContext(context ldcontext.Context) m.Matcher

func IsIndexEvent

func IsIndexEvent() m.Matcher

func IsIndexEventForContext

func IsIndexEventForContext(context ldcontext.Context) m.Matcher

func IsSummaryEvent

func IsSummaryEvent() m.Matcher

func IsValidFeatureEventWithConditions

func IsValidFeatureEventWithConditions(matchers ...m.Matcher) m.Matcher

func IsValidSummaryEventWithFlags

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

func JSONPropertyKeysCanOnlyBe

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

func JSONPropertyNullOrAbsent

func JSONPropertyNullOrAbsent(name string) m.Matcher

func RedactedAttributesAre

func RedactedAttributesAre(attrStrings ...string) m.Matcher

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 RunParameterizedServerSideClientNotReadyEvalTests

func RunParameterizedServerSideClientNotReadyEvalTests(t *ldtest.T)

func RunParameterizedServerSideEvalTests

func RunParameterizedServerSideEvalTests(t *ldtest.T)

func RunServerSideEvalAllFlagsTests

func RunServerSideEvalAllFlagsTests(t *ldtest.T)

func RunServerSideTestSuite

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

func SortedStrings

func SortedStrings() m.MatcherTransform

func ValueIsPositiveNonZeroInteger

func ValueIsPositiveNonZeroInteger() m.Matcher

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

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

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

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

ContextBuild tells the test service to use the SDK's context builder to build a context and return it as JSON.

func (*SDKClient) ContextConvert

ContextConvert tells the test service to use the SDK's JSON converters to unmarshal and remarshal a context.

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

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.

func (*SDKClient) SendIdentifyEvent

func (c *SDKClient) SendIdentifyEvent(t *ldtest.T, context ldcontext.Context)

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.

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
}

Jump to

Keyboard shortcuts

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