Documentation ¶
Overview ¶
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.
Index ¶
- func DiffAppStates(expected, actual view.AppState) string
- func DiffModuleStates(expected, actual view.ModuleState) string
- func DiffObjectCollections(expected, actual view.ObjectCollection) string
- type App
- func (a *App) ApplyUpdate(data appdata.ObjectUpdateData) error
- func (a *App) GetModule(moduleName string) (view.ModuleState, error)
- func (a *App) InitializeModule(data appdata.ModuleInitializationData) error
- func (a *App) Modules(f func(modState view.ModuleState, err error) bool)
- func (a *App) NumModules() (int, error)
- func (a *App) UpdateGen() *rapid.Generator[appdata.ObjectUpdateData]
- type Module
- func (o *Module) ApplyUpdate(update schema.StateObjectUpdate) error
- func (o *Module) GetObjectCollection(objectType string) (view.ObjectCollection, error)
- func (o *Module) ModuleName() string
- func (o *Module) ModuleSchema() schema.ModuleSchema
- func (o *Module) NumObjectCollections() (int, error)
- func (o *Module) ObjectCollections(f func(value view.ObjectCollection, err error) bool)
- func (o *Module) UpdateGen() *rapid.Generator[schema.StateObjectUpdate]
- type ObjectCollection
- func (o *ObjectCollection) AllState(f func(schema.StateObjectUpdate, error) bool)
- func (o *ObjectCollection) ApplyUpdate(update schema.StateObjectUpdate) error
- func (o *ObjectCollection) GetObject(key interface{}) (update schema.StateObjectUpdate, found bool, err error)
- func (o *ObjectCollection) Len() (int, error)
- func (o *ObjectCollection) ObjectType() schema.StateObjectType
- func (o *ObjectCollection) UpdateGen() *rapid.Generator[schema.StateObjectUpdate]
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffAppStates ¶
DiffAppStates compares the app state of two objects that implement AppState and returns a string with a diff if they are different or the empty string if they are the same.
func DiffModuleStates ¶
func DiffModuleStates(expected, actual view.ModuleState) string
DiffModuleStates compares the module state of two objects that implement ModuleState and returns a string with a diff if they are different or the empty string if they are the same.
func DiffObjectCollections ¶
func DiffObjectCollections(expected, actual view.ObjectCollection) string
DiffObjectCollections compares the object collection state of two objects that implement ObjectCollectionState and returns a string with a diff if they are different or the empty string if they are the same.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is a collection of simulated module states corresponding to an app's schema for testing purposes.
func NewApp ¶
func NewApp(appSchema map[string]schema.ModuleSchema, options Options) *App
NewApp creates a new simulation App for the given app schema. The app schema can be nil if the user desires initializing modules with InitializeModule instead.
func (*App) ApplyUpdate ¶
func (a *App) ApplyUpdate(data appdata.ObjectUpdateData) error
ApplyUpdate applies the given object update to the module.
func (*App) GetModule ¶
func (a *App) GetModule(moduleName string) (view.ModuleState, error)
GetModule returns the module state for the given module name.
func (*App) InitializeModule ¶
func (a *App) InitializeModule(data appdata.ModuleInitializationData) error
InitializeModule initializes the module with the provided schema. This returns an error if the module is already initialized in state.
func (*App) Modules ¶
func (a *App) Modules(f func(modState view.ModuleState, err error) bool)
Modules iterates over all the module state instances in the app.
func (*App) NumModules ¶
NumModules returns the number of modules in the app.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is a collection of object collections corresponding to a module's schema for testing purposes.
func NewModule ¶
func NewModule(name string, moduleSchema schema.ModuleSchema, options Options) *Module
NewModule creates a new Module for the given module schema.
func (*Module) ApplyUpdate ¶
func (o *Module) ApplyUpdate(update schema.StateObjectUpdate) error
ApplyUpdate applies the given object update to the module.
func (*Module) GetObjectCollection ¶
func (o *Module) GetObjectCollection(objectType string) (view.ObjectCollection, error)
GetObjectCollection returns the object collection for the given object type.
func (*Module) ModuleName ¶
ModuleName returns the name of the module.
func (*Module) ModuleSchema ¶
func (o *Module) ModuleSchema() schema.ModuleSchema
ModuleSchema returns the module schema for the module.
func (*Module) NumObjectCollections ¶
NumObjectCollections returns the number of object collections in the module.
func (*Module) ObjectCollections ¶
func (o *Module) ObjectCollections(f func(value view.ObjectCollection, err error) bool)
ObjectCollections iterates over all object collections in the module.
type ObjectCollection ¶
type ObjectCollection struct {
// contains filtered or unexported fields
}
ObjectCollection is a collection of state objects of a specific type for testing purposes.
func NewObjectCollection ¶
func NewObjectCollection(objectType schema.StateObjectType, options Options, typeSet schema.TypeSet) *ObjectCollection
NewObjectCollection creates a new ObjectCollection for the given object type.
func (*ObjectCollection) AllState ¶
func (o *ObjectCollection) AllState(f func(schema.StateObjectUpdate, error) bool)
AllState iterates over the state of the collection by calling the given function with each item in state represented as an object update.
func (*ObjectCollection) ApplyUpdate ¶
func (o *ObjectCollection) ApplyUpdate(update schema.StateObjectUpdate) error
ApplyUpdate applies the given object update to the collection.
func (*ObjectCollection) GetObject ¶
func (o *ObjectCollection) GetObject(key interface{}) (update schema.StateObjectUpdate, found bool, err error)
GetObject returns the object with the given key from the collection represented as an StateObjectUpdate itself. Deletions that are retained are returned as StateObjectUpdate's with delete set to true.
func (*ObjectCollection) Len ¶
func (o *ObjectCollection) Len() (int, error)
Len returns the number of objects in the collection.
func (*ObjectCollection) ObjectType ¶
func (o *ObjectCollection) ObjectType() schema.StateObjectType
ObjectType returns the object type of the collection.
func (*ObjectCollection) UpdateGen ¶
func (o *ObjectCollection) UpdateGen() *rapid.Generator[schema.StateObjectUpdate]
UpdateGen returns a generator for random object updates against the collection. This generator is stateful and returns a certain number of updates and deletes to existing objects.
type Options ¶
type Options struct { // CanRetainDeletions indicates that the simulator can retain deletions when that flag is enabled // on object types. This should be set to match the indexers ability to retain deletions or not // for accurately testing the expected state in the simulator with the indexer's actual state. CanRetainDeletions bool }
Options are options for object, module and app state simulators.