Documentation ¶
Overview ¶
Package schematesting includes property-based testing generators for creating random valid data for testing schemas and state representing those schemas.
Index ¶
- Variables
- func CompareKindValues(kind schema.Kind, expected, actual any) (bool, error)
- func DiffFieldValues(field schema.Field, expected, actual any) string
- func DiffObjectKeys(fields []schema.Field, expected, actual any) string
- func DiffObjectValues(fields []schema.Field, expected, actual any) string
- func EnumType() *rapid.Generator[schema.EnumType]
- func FieldGen(typeSet schema.TypeSet) *rapid.Generator[schema.Field]
- func FieldValueGen(field schema.Field, typeSet schema.TypeSet) *rapid.Generator[any]
- func KeyFieldGen(typeSet schema.TypeSet) *rapid.Generator[schema.Field]
- func ModuleSchemaGen() *rapid.Generator[schema.ModuleSchema]
- func ObjectKeyGen(keyFields []schema.Field, typeSet schema.TypeSet) *rapid.Generator[any]
- func ObjectKeyString(objectType schema.StateObjectType, key any) string
- func ObjectValueGen(valueFields []schema.Field, forUpdate bool, typeSet schema.TypeSet) *rapid.Generator[any]
- func StateObjectInsertGen(objectType schema.StateObjectType, typeSet schema.TypeSet) *rapid.Generator[schema.StateObjectUpdate]
- func StateObjectTypeGen(typeSet schema.TypeSet) *rapid.Generator[schema.StateObjectType]
- func StateObjectUpdateGen(objectType schema.StateObjectType, ...) *rapid.Generator[schema.StateObjectUpdate]
Constants ¶
This section is empty.
Variables ¶
var AppSchemaGen = rapid.Custom(func(t *rapid.T) map[string]schema.ModuleSchema { schema := make(map[string]schema.ModuleSchema) numModules := rapid.IntRange(1, 10).Draw(t, "numModules") for i := 0; i < numModules; i++ { moduleName := NameGen.Draw(t, "moduleName") moduleSchema := ModuleSchemaGen().Draw(t, fmt.Sprintf("moduleSchema[%s]", moduleName)) schema[moduleName] = moduleSchema } return schema })
AppSchemaGen generates random valid app schemas, essentially a map of module names to module schemas.
var ExampleAppSchema = map[string]schema.ModuleSchema{ "all_kinds": mkAllKindsModule(), "test_cases": schema.MustCompileModuleSchema( schema.StateObjectType{ Name: "Singleton", KeyFields: []schema.Field{}, ValueFields: []schema.Field{ { Name: "Value", Kind: schema.StringKind, }, { Name: "Value2", Kind: schema.BytesKind, }, }, }, schema.StateObjectType{ Name: "Simple", KeyFields: []schema.Field{ { Name: "Key", Kind: schema.StringKind, }, }, ValueFields: []schema.Field{ { Name: "Value1", Kind: schema.Int32Kind, }, { Name: "Value2", Kind: schema.BytesKind, }, }, }, schema.StateObjectType{ Name: "TwoKeys", KeyFields: []schema.Field{ { Name: "Key1", Kind: schema.StringKind, }, { Name: "Key2", Kind: schema.Int32Kind, }, }, }, schema.StateObjectType{ Name: "ThreeKeys", KeyFields: []schema.Field{ { Name: "Key1", Kind: schema.StringKind, }, { Name: "Key2", Kind: schema.Int32Kind, }, { Name: "Key3", Kind: schema.Uint64Kind, }, }, ValueFields: []schema.Field{ { Name: "Value1", Kind: schema.Int32Kind, }, }, }, schema.StateObjectType{ Name: "ManyValues", KeyFields: []schema.Field{ { Name: "Key", Kind: schema.StringKind, }, }, ValueFields: []schema.Field{ { Name: "Value1", Kind: schema.Int32Kind, }, { Name: "Value2", Kind: schema.BytesKind, }, { Name: "Value3", Kind: schema.Float64Kind, }, { Name: "Value4", Kind: schema.Uint64Kind, }, }, }, schema.StateObjectType{ Name: "RetainDeletions", KeyFields: []schema.Field{ { Name: "Key", Kind: schema.StringKind, }, }, ValueFields: []schema.Field{ { Name: "Value1", Kind: schema.Int32Kind, }, { Name: "Value2", Kind: schema.BytesKind, }, }, RetainDeletions: true, }, ), }
ExampleAppSchema is an example app schema that intends to cover all schema cases that indexers should handle that can be used in reproducible unit testing and property based testing.
var NameGen = rapid.StringMatching(schema.NameFormat)
NameGen validates valid names that match the NameFormat regex.
Functions ¶
func CompareKindValues ¶
CompareKindValues compares the expected and actual values for the provided kind and returns true if they are equal, false if they are not, and an error if the types are not valid for the kind. For IntegerKind and DecimalKind values, comparisons are made based on equality of the underlying numeric values rather than their string encoding.
func DiffFieldValues ¶
DiffFieldValues compares the values for the provided field and returns a diff if they differ or an empty string if they are equal.
func DiffObjectKeys ¶
DiffObjectKeys compares the values as object keys for the provided field and returns a diff if they differ or an empty string if they are equal.
func DiffObjectValues ¶
DiffObjectValues compares the values as object values for the provided field and returns a diff if they differ or an empty string if they are equal. Object values cannot be ValueUpdates for this comparison.
func FieldValueGen ¶
FieldValueGen generates random valid values for the field, aiming to exercise the full range of possible values for the field.
func KeyFieldGen ¶
KeyFieldGen generates random key fields based on the validity criteria of key fields.
func ModuleSchemaGen ¶
func ModuleSchemaGen() *rapid.Generator[schema.ModuleSchema]
ModuleSchemaGen generates random ModuleSchema's based on the validity criteria of module schemas.
func ObjectKeyGen ¶
ObjectKeyGen generates a value that is valid for the provided object key fields.
func ObjectKeyString ¶
func ObjectKeyString(objectType schema.StateObjectType, key any) string
ObjectKeyString formats the object key as a string deterministically for storage in a map. The key must be valid for the object type and the object type must be valid. No validation is performed here.
func ObjectValueGen ¶
func ObjectValueGen(valueFields []schema.Field, forUpdate bool, typeSet schema.TypeSet) *rapid.Generator[any]
ObjectValueGen generates a value that is valid for the provided object value fields. The forUpdate parameter indicates whether the generator should generate value that are valid for insertion (in the case forUpdate is false) or for update (in the case forUpdate is true). Values that are for update may skip some fields in a ValueUpdates instance whereas values for insertion will always contain all values.
func StateObjectInsertGen ¶
func StateObjectInsertGen(objectType schema.StateObjectType, typeSet schema.TypeSet) *rapid.Generator[schema.StateObjectUpdate]
StateObjectInsertGen generates object updates that are valid for insertion.
func StateObjectTypeGen ¶
StateObjectTypeGen generates random StateObjectType's based on the validity criteria of object types.
func StateObjectUpdateGen ¶
func StateObjectUpdateGen(objectType schema.StateObjectType, state *btree.Map[string, schema.StateObjectUpdate], sch schema.TypeSet) *rapid.Generator[schema.StateObjectUpdate]
StateObjectUpdateGen generates object updates that are valid for updates using the provided state map as a source of valid existing keys.
Types ¶
This section is empty.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package appdatasim contains utilities for simulating valid streams of app data for testing indexer implementations.
|
Package appdatasim contains utilities for simulating valid streams of app data for testing indexer implementations. |
Package statesim contains utilities for simulating state based on ObjectType's and ModuleSchema's for testing the conformance of state management libraries and indexers to schema rules.
|
Package statesim contains utilities for simulating state based on ObjectType's and ModuleSchema's for testing the conformance of state management libraries and indexers to schema rules. |