sharedtest

package
v7.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package sharedtest contains types and functions used by SDK unit tests in multiple packages.

Since it is inside internal/, none of this code can be seen by application code and it can be freely changed without breaking any public APIs. Test helpers that we want to be available to application code should be in testhelpers/ instead.

It is important that no non-test code ever imports this package, so that it will not be compiled into applications as a transitive dependency.

Note that this package is not allowed to reference the "internal" package, because the tests in that package use sharedtest helpers so it would be a circular reference.

Index

Constants

View Source
const (
	// HookStageBeforeEvaluation is the stage executed before evaluation.
	HookStageBeforeEvaluation = HookStage("before")
	// HookStageAfterEvaluation is the stage executed after evaluation.
	HookStageAfterEvaluation = HookStage("after")
)

Variables

This section is empty.

Functions

func DataSetToMap

DataSetToMap converts the data format for Init into a map of maps.

func ExpectFlagChangeEvents

func ExpectFlagChangeEvents(t *testing.T, ch <-chan interfaces.FlagChangeEvent, keys ...string)

ExpectFlagChangeEvents asserts that a channel receives flag change events for the specified keys (in any order) and then does not receive any more events for the next 100ms.

func FlagDescriptor

FlagDescriptor is a shortcut for creating a StoreItemDescriptor from a flag.

func NewSimpleTestContext

func NewSimpleTestContext(sdkKey string) subsystems.ClientContext

NewSimpleTestContext returns a basic implementation of interfaces.ClientContext for use in test code.

func NewTestContext

func NewTestContext(
	sdkKey string,
	optHTTPConfig *subsystems.HTTPConfiguration,
	optLoggingConfig *subsystems.LoggingConfiguration,
) subsystems.BasicClientContext

NewTestContext returns a basic implementation of interfaces.ClientContext for use in test code. We can't use internal.NewClientContextImpl for this because of circular references.

func NewTestLoggers

func NewTestLoggers() ldlog.Loggers

NewTestLoggers returns a standardized logger instance used by unit tests. If you want to temporarily enable log output for tests, change testLogLevel to for instance ldlog.Debug. Note that "go test" normally suppresses output anyway unless a test fails.

func NormalizeDataSet

func NormalizeDataSet(in []ldstoretypes.Collection) []ldstoretypes.Collection

NormalizeDataSet sorts the data set by kind and key for test determinacy.

func SegmentDescriptor

func SegmentDescriptor(s ldmodel.Segment) ldstoretypes.ItemDescriptor

SegmentDescriptor is a shortcut for creating a StoreItemDescriptor from a segment.

func TestLoggingConfig

func TestLoggingConfig() subsystems.LoggingConfiguration

TestLoggingConfig returns a LoggingConfiguration corresponding to NewTestLoggers().

Types

type DataSetBuilder

type DataSetBuilder struct {
	// contains filtered or unexported fields
}

DataSetBuilder is a helper for creating collections of flags and segments.

func NewDataSetBuilder

func NewDataSetBuilder() *DataSetBuilder

NewDataSetBuilder creates a DataSetBuilder.

func (*DataSetBuilder) Build

func (d *DataSetBuilder) Build() []ldstoretypes.Collection

Build returns the built data sest.

func (*DataSetBuilder) Flags

func (d *DataSetBuilder) Flags(flags ...ldmodel.FeatureFlag) *DataSetBuilder

Flags adds flags to the data set.

func (*DataSetBuilder) Segments

func (d *DataSetBuilder) Segments(segments ...ldmodel.Segment) *DataSetBuilder

Segments adds segments to the data set.

func (*DataSetBuilder) ToServerSDKData

func (d *DataSetBuilder) ToServerSDKData() *ldservices.ServerSDKData

ToServerSDKData converts the data set to the format used by the ldservices helpers.

type HookEvalCapture added in v7.3.0

type HookEvalCapture struct {
	GoContext               context.Context
	EvaluationSeriesContext ldhooks.EvaluationSeriesContext
	EvaluationSeriesData    ldhooks.EvaluationSeriesData
	Detail                  ldreason.EvaluationDetail
}

HookEvalCapture is used to capture the information provided to a hook during execution.

type HookExpectedCall added in v7.3.0

type HookExpectedCall struct {
	HookStage   HookStage
	EvalCapture HookEvalCapture
}

HookExpectedCall represents an expected call to a hook.

type HookStage added in v7.3.0

type HookStage string

HookStage is the stage of a hook being executed.

type TestHook added in v7.3.0

TestHook is a hook for testing to be used only by the SDK tests.

func NewTestHook added in v7.3.0

func NewTestHook(name string) TestHook

NewTestHook creates a new test hook.

func (TestHook) AfterEvaluation added in v7.3.0

AfterEvaluation testing implementation of the AfterEvaluation stage.

func (TestHook) BeforeEvaluation added in v7.3.0

BeforeEvaluation testing implementation of the BeforeEvaluation stage.

func (TestHook) Metadata added in v7.3.0

func (h TestHook) Metadata() ldhooks.Metadata

Metadata gets the meta-data for the hook.

func (TestHook) Verify added in v7.3.0

func (h TestHook) Verify(t *testing.T, calls ...HookExpectedCall)

Verify is used to verify that the hook received calls it expected.

func (TestHook) VerifyNoCalls added in v7.3.0

func (h TestHook) VerifyNoCalls(t *testing.T)

VerifyNoCalls will assert if the hook has received any calls.

Directories

Path Synopsis
Package mocks contains mocks/spies used within SDK unit tests.
Package mocks contains mocks/spies used within SDK unit tests.

Jump to

Keyboard shortcuts

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