Documentation ¶
Overview ¶
Package data contains functions for reading test data files. The actual data files are in subdirectories of data/data-files.
Index ¶
- func AllJSONValueTypes() []ldvalue.ValueType
- func AllSDKValueTypes() []servicedef.ValueType
- func ClientSideFlagShouldHaveDebuggingEnabledUntil(t time.Time) func(*mockld.ClientSDKFlagWithKey)
- func ClientSideFlagShouldHaveEvalReason(reason ldreason.EvaluationReason) func(*mockld.ClientSDKFlagWithKey)
- func ClientSideFlagShouldHaveFullEventTracking(f *mockld.ClientSDKFlagWithKey)
- func FlagShouldAlwaysHaveDebuggingEnabled(builder *ldbuilders.FlagBuilder)
- func FlagShouldHaveDebuggingEnabledUntil(t time.Time) func(*ldbuilders.FlagBuilder)
- func FlagShouldHaveFullEventTracking(builder *ldbuilders.FlagBuilder)
- func FlagShouldProduceThisEvalReason(reason ldreason.EvaluationReason, matchContexts ...ldcontext.Context) func(*ldbuilders.FlagBuilder)
- func GroupTestSuitesByName[V HasName](suites []V) [][]V
- func LoadAndParseAllTestSuites[V any](t *ldtest.T, dirName string) []V
- func MakeStandardMigrationStages() []ldvalue.Value
- func MakeStandardTestValues() []ldvalue.Value
- func ParseJSONOrYAML(data []byte, target interface{}) error
- type ClientSideFlagFactory
- type ContextFactory
- func NewContextFactoriesForExercisingAllAttributes(prefix string) []*ContextFactory
- func NewContextFactoriesForSingleAndMultiKind(prefix string, builderActions ...func(*ldcontext.Builder)) []*ContextFactory
- func NewContextFactory(prefix string, builderActions ...func(*ldcontext.Builder)) *ContextFactory
- func NewMultiContextFactory(prefix string, kinds []ldcontext.Kind, ...) *ContextFactory
- type FlagFactory
- type GenericFactory
- type HasName
- type MemoizingFactory
- func NewMemoizingClientSideFlagFactory(startingVersion int, ...) *MemoizingFactory[servicedef.ValueType, mockld.ClientSDKFlagWithKey]
- func NewMemoizingFlagFactory(startingVersion int, factoryFn func(servicedef.ValueType) ldmodel.FeatureFlag) *MemoizingFactory[servicedef.ValueType, ldmodel.FeatureFlag]
- type SourceInfo
- type ValueFactoryBySDKValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllJSONValueTypes ¶
AllJSONValueTypes returns every possible value of the ldvalue.ValueType enum, corresponding to the standard JSON types (including null).
func AllSDKValueTypes ¶
func AllSDKValueTypes() []servicedef.ValueType
AllSDKValueTypes returns every possible value of the servicedef.ValueType enum, corresponding to the logical types used in strongly-typed SDK APIs-- that is, the result types you could request when evaluating a flag. So, unlike AllJSONValueTypes, int and double are different, there is no null, and the "any" type is used for arbitrary JSON values.
func ClientSideFlagShouldHaveDebuggingEnabledUntil ¶
func ClientSideFlagShouldHaveDebuggingEnabledUntil(t time.Time) func(*mockld.ClientSDKFlagWithKey)
ClientSideFlagShouldHaveDebuggingEnabledUntil is a convenience function for configuring a client-side flag to have debugging enabled until the specified time.
func ClientSideFlagShouldHaveEvalReason ¶
func ClientSideFlagShouldHaveEvalReason(reason ldreason.EvaluationReason) func(*mockld.ClientSDKFlagWithKey)
ClientSideFlagShouldHaveEvalReason is a convenience function for configuring a client-side flag to have an evaluation reason.
func ClientSideFlagShouldHaveFullEventTracking ¶
func ClientSideFlagShouldHaveFullEventTracking(f *mockld.ClientSDKFlagWithKey)
ClientSideFlagShouldHaveFullEventTracking is a convenience function for configuring a client-side flag to have full event tracking enabled (by setting TrackEvents to true).
func FlagShouldAlwaysHaveDebuggingEnabled ¶
func FlagShouldAlwaysHaveDebuggingEnabled(builder *ldbuilders.FlagBuilder)
FlagShouldAlwaysHaveDebuggingEnabled is a convenience function for configuring a flag to have debugging enabled (by setting DebugEventsUntilDate to a far future time).
func FlagShouldHaveDebuggingEnabledUntil ¶
func FlagShouldHaveDebuggingEnabledUntil(t time.Time) func(*ldbuilders.FlagBuilder)
FlagShouldHaveDebuggingEnabledUntil is a convenience function for configuring a flag to have debugging enabled until the specified time.
func FlagShouldHaveFullEventTracking ¶
func FlagShouldHaveFullEventTracking(builder *ldbuilders.FlagBuilder)
FlagShouldHaveFullEventTracking is a convenience function for configuring a flag to have full event tracking enabled (by setting TrackEvents to true).
func FlagShouldProduceThisEvalReason ¶
func FlagShouldProduceThisEvalReason( reason ldreason.EvaluationReason, matchContexts ...ldcontext.Context, ) func(*ldbuilders.FlagBuilder)
FlagShouldProduceThisEvalReason is a convenience function for configuring a flag to produce a specific evaluation reason for all evaluations. If specific contexts should be matched, pass them in matchContexts-- however, this implementation only works if they are single-kind contexts that are all of the same kind.
func GroupTestSuitesByName ¶
func GroupTestSuitesByName[V HasName](suites []V) [][]V
GroupTestSuitesByName converts a list of test suites to a list of lists, grouped by their name property.
See comments in common_tests_eval.go for an example of why we may want to do this.
func LoadAndParseAllTestSuites ¶
LoadAndParseAllTestSuites calls LoadAllDataFiles and then parses each of the resulting SourceInfos as JSON or YAML into the specified type.
func MakeStandardMigrationStages ¶ added in v2.2.0
MakeStandardMigrationStages returns a list of all valid migration stages in the order of progression.
func MakeStandardTestValues ¶
MakeStandardTestValues returns a list of values that cover all JSON types, *and* all special values that might conceivably be handled wrong in SDK implementations. For instance, we should check both non-empty and empty strings, and both zero and non-zero numbers, to make sure "" and 0 ares not being treated the same as "undefined/null".
func ParseJSONOrYAML ¶
ParseJSONOrYAML is used in the same way as json.Unmarshal, but if the data is YAML and not JSON, it will convert the YAML to JSON and then parse it as JSON.
Types ¶
type ClientSideFlagFactory ¶
type ClientSideFlagFactory struct {
// contains filtered or unexported fields
}
ClientSideFlagFactory is a test data generator that produces mockld.ClientSDKFlagWithKey instances.
func NewClientSideFlagFactory ¶
func NewClientSideFlagFactory( keyPrefix string, valueFactory ValueFactoryBySDKValueType, builderActions ...func(*mockld.ClientSDKFlagWithKey), ) *ClientSideFlagFactory
NewClientSideFlagFactory creates a ClientSideFlagFactory with the specified configuration.
The valueFactory parameter provides the value that each flag will return for evaluations. The builderActions, if any, will be run each time a flag is created. Each flag will have a unique key beginning with the specified prefix.
func (*ClientSideFlagFactory) MakeFlagForValueType ¶
func (f *ClientSideFlagFactory) MakeFlagForValueType(valueType servicedef.ValueType) mockld.ClientSDKFlagWithKey
MakeFlagForValueType creates a new flag configuration. The flag variation will be of the specified type.
func (*ClientSideFlagFactory) ReuseFlagForValueType ¶
func (f *ClientSideFlagFactory) ReuseFlagForValueType(valueType servicedef.ValueType) mockld.ClientSDKFlagWithKey
ReuseFlagForValueType is the same as MakeFlagForValueType except that if MakeFlagForValueType has already been called for the same type, it will return the same flag and not create a new one.
type ContextFactory ¶
type ContextFactory struct {
// contains filtered or unexported fields
}
ContextFactory is a test data generator that produces ldcontext.Context instances.
func NewContextFactoriesForExercisingAllAttributes ¶
func NewContextFactoriesForExercisingAllAttributes( prefix string, ) []*ContextFactory
NewContextFactoriesForExercisingAllAttributes produces a list of ContextFactory instances that use different subsets of the context schema, to verify that context attributes are encoded correctly when they are sent to evaluation endpoints.
The returned list will include factories for 1. single-kind Contexts with no attributes other than kind and key, 2. single-kind Contexts with every possible kind of attribute, 3. multi-kind Contexts that combine 1 and 2.
Each will have an appropriate Description, so the logic for running a test against each one can look like this:
for _, contexts := range data.NewContextFactoriesForExercisingAllAttributes("NameOfTest") { t.Run(contexts.Description(), func(t *testing.T) { context := contexts.NextUniqueContext() // do something with this }) }
func NewContextFactoriesForSingleAndMultiKind ¶
func NewContextFactoriesForSingleAndMultiKind( prefix string, builderActions ...func(*ldcontext.Builder), ) []*ContextFactory
NewContextFactoriesForSingleAndMultiKind produces a list of ContextFactory instances for testing SDK functionality that may behave differently for different Context variants.
The returned list will include factories for 1. single-kind Contexts of the default kind, 2. single-kind Contexts of a different kind, 3. multi-kind Contexts. The reason for checking single vs. multi-kind is that we want to make sure the SDK correctly enumerates the kinds when it populates the contextKeys property in event data. The reason for checking the default kind vs. a non-default kind is that it affects the deduplication logic for index events.
Each will have an appropriate Description, so the logic for running a test against each one can look like this:
for _, contexts := range data.NewContextFactoriesForSingleAndMultiKind("NameOfTest") { t.Run(contexts.Description(), func(t *testing.T) { context := contexts.NextUniqueContext() // do something with this }) }
func NewContextFactory ¶
func NewContextFactory(prefix string, builderActions ...func(*ldcontext.Builder)) *ContextFactory
NewContextFactory creates a ContextFactory that produces single-kind Contexts.
Each generated Context will have a unique key that starts with the prefix string. The builderActions, if any, will be run against the builder for each Context. If no actions are specified, then it will have no properties other than the key, and its kind will be ldcontext.DefaultKind ("user").
func NewMultiContextFactory ¶
func NewMultiContextFactory( prefix string, kinds []ldcontext.Kind, builderActions ...func(*ldcontext.Builder), ) *ContextFactory
NewMultiContextFactory creates a ContextFactory that produces multi-kind Contexts.
Each generated multiple context will contain an individual context for each of the kinds in the kinds parameter. If builderActions are specified, the first one will be run for the first kind, the second for the second, etc. Each individual context will have a unique key that starts with the prefix string.
func (*ContextFactory) Description ¶
func (f *ContextFactory) Description() string
Description returns a descriptive string, if this ContextFactory was produced by a method such as NewContextFactoriesForSingleAndMultiKind that provides one.
func (*ContextFactory) NextUniqueContext ¶
func (f *ContextFactory) NextUniqueContext() ldcontext.Context
NextUniqueContext creates a Context instance.
func (*ContextFactory) Prefix ¶
func (f *ContextFactory) Prefix() string
func (*ContextFactory) SetKeyDisambiguatorValueSameAs ¶
func (f *ContextFactory) SetKeyDisambiguatorValueSameAs(f1 *ContextFactory)
SetKeyDisambiguatorValueSameAs overrides the usual "add a randomized value to all the keys produced by this factory" logic, which is meant to avoid key collisions, so that these two factories will use the *same* randomized value. This is for tests where we want to verify, for instance, that two contexts with the same key but different kinds are treated as distinct.
type FlagFactory ¶
type FlagFactory struct {
// contains filtered or unexported fields
}
FlagFactory is a test data generator that produces ldmodel.FeatureFlag instances.
func NewFlagFactory ¶
func NewFlagFactory( keyPrefix string, valueFactory ValueFactoryBySDKValueType, builderActions ...func(*ldbuilders.FlagBuilder), ) *FlagFactory
NewFlagFactory creates a FlagFactory with the specified configuration.
The valueFactory parameter provides the value that each flag will return for evaluations. The builderActions, if any, will be run each time a flag is created. Each flag will have a unique key beginning with the specified prefix.
func (*FlagFactory) MakeFlag ¶
func (f *FlagFactory) MakeFlag() ldmodel.FeatureFlag
MakeFlag creates a new flag configuration. Use this when the value type is not significant to the test; it will default to using string variations, since those are more easily readable in test output.
func (*FlagFactory) MakeFlagForValueType ¶
func (f *FlagFactory) MakeFlagForValueType(valueType servicedef.ValueType) ldmodel.FeatureFlag
MakeFlagForValueType creates a new flag configuration. The flag variations will be of the specified type.
func (*FlagFactory) ReuseFlagForValueType ¶
func (f *FlagFactory) ReuseFlagForValueType(valueType servicedef.ValueType) ldmodel.FeatureFlag
ReuseFlagForValueType is the same as MakeFlagForValueType except that if MakeFlagForValueType has already been called for the same type, it will return the same flag and not create a new one.
type GenericFactory ¶
type GenericFactory[ParamT, ResultT any] interface { Get(param ParamT) ResultT }
type MemoizingFactory ¶
type MemoizingFactory[ParamT comparable, ResultT any] struct { // contains filtered or unexported fields }
func NewMemoizingClientSideFlagFactory ¶
func NewMemoizingClientSideFlagFactory( startingVersion int, factoryFn func(servicedef.ValueType) mockld.ClientSDKFlagWithKey, ) *MemoizingFactory[servicedef.ValueType, mockld.ClientSDKFlagWithKey]
func NewMemoizingFlagFactory ¶
func NewMemoizingFlagFactory( startingVersion int, factoryFn func(servicedef.ValueType) ldmodel.FeatureFlag, ) *MemoizingFactory[servicedef.ValueType, ldmodel.FeatureFlag]
func (*MemoizingFactory[P, R]) Create ¶
func (f *MemoizingFactory[P, R]) Create(param P) R
func (*MemoizingFactory[P, R]) GetOrCreate ¶
func (f *MemoizingFactory[P, R]) GetOrCreate(param P) R
type SourceInfo ¶
type SourceInfo struct { FilePath string BaseName string Params map[string]ldvalue.Value Data []byte }
SourceInfo represents JSON or YAML data that was read from a file, after post-processing to expand constants and parameters. For non-parameterized tests, you will get one SourceInfo per file. For parameterized tests, there can be many instances per file, each with its own version of Data. See ReadFile and docs/data_files.md.
func LoadAllDataFiles ¶
func LoadAllDataFiles(path string) ([]SourceInfo, error)
LoadAllDataFiles reads all data files in a directory and performs any necessary constant/parameter substitutions. It can return more than one SourceInfo per file, because any file can be a parameterized test. See docs/data_files.md.
The path parameter is relative to data/data-files.
func LoadDataFile ¶
func LoadDataFile(path string) ([]SourceInfo, error)
LoadDataFile reads a data file and performs any necessary constant/parameter substitutions. It can return more than one SourceInfo because any file can be a parameterized test. See docs/data_files.md.
The path parameter is relative to data/data-files.
func (SourceInfo) ParamsString ¶
func (s SourceInfo) ParamsString() string
func (SourceInfo) ParseInto ¶
func (s SourceInfo) ParseInto(target interface{}) error
type ValueFactoryBySDKValueType ¶
type ValueFactoryBySDKValueType func(valueType servicedef.ValueType) ldvalue.Value
ValueFactoryBySDKValueType is a data generator function type that produces a different ldvalue.Value for each of the logical types supported by strongly-typed SDKs.
func MakeValueFactoriesBySDKValueType ¶
func MakeValueFactoriesBySDKValueType(howMany int) []ValueFactoryBySDKValueType
MakeValueFactoriesBySDKValueType creates the specified number of ValueByTypeFactory generators, each producing different values from the others (insofar as possible, given that there are only two possible values for the boolean type).
func MakeValueFactoryBySDKValueType ¶
func MakeValueFactoryBySDKValueType() ValueFactoryBySDKValueType
MakeValueFactoryBySDKValueType creates a ValueByTypeFactory generator providing a different value for each servicedef.ValueType.
func SingleValueForAllSDKValueTypes ¶
func SingleValueForAllSDKValueTypes(value ldvalue.Value) ValueFactoryBySDKValueType
SingleValueForAllSDKValueTypes creates a ValueByTypeFactory generator that always returns the same value.