statesim

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiffAppStates

func DiffAppStates(expected, actual view.AppState) string

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

func (a *App) NumModules() (int, error)

NumModules returns the number of modules in the app.

func (*App) UpdateGen

func (a *App) UpdateGen() *rapid.Generator[appdata.ObjectUpdateData]

UpdateGen is a generator for object update data against the app. It is stateful and includes a certain number of updates and deletions to existing objects.

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

func (o *Module) ModuleName() string

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

func (o *Module) NumObjectCollections() (int, error)

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.

func (*Module) UpdateGen

func (o *Module) UpdateGen() *rapid.Generator[schema.StateObjectUpdate]

UpdateGen returns a generator for object updates. The generator is stateful and returns a certain number of updates and deletes of existing objects 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

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.

Jump to

Keyboard shortcuts

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