README
¶
Package servicetest
This package provides basic building blocks for testing your superwatcher-based services.
The idea here is you test your services by running it against a known environment,
which in this case is JSON log files using reorgsim
chain simulation.
See demotest for usage examples.
Most of the name definitions are public, so users can have to items defined here,
such as struct DebugEngine
and function RunService
.
The most basic way to use testutils is to call RunService
with a superwatcher.Emitter
and superwatcher.Engine
,
although it's better to use TestCase
for multiple test cases.
Users should rely on this package in addition to their own unit tests, especially if the services in question are poller-type services.
Documentation
¶
Index ¶
- func DefaultServiceTestConfig(startBlock uint64, logLevel uint8, policy superwatcher.Policy) *superwatcher.Config
- func RunService(emitter superwatcher.Emitter, engine superwatcher.Engine) error
- func RunServiceTestComponents(tc *TestComponents) (superwatcher.GetStateDataGateway, error)
- type DebugServiceEngine
- func (e *DebugServiceEngine) HandleEmitterError(err error) error
- func (e *DebugServiceEngine) HandleGoodLogs(logs []*types.Log, artifacts []superwatcher.Artifact) ([]superwatcher.Artifact, error)
- func (e *DebugServiceEngine) HandleReorgedLogs(logs []*types.Log, artifacts []superwatcher.Artifact) ([]superwatcher.Artifact, error)
- func (e *DebugServiceEngine) HandleResult(result *superwatcher.PollerResult) error
- type TestCase
- type TestComponents
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultServiceTestConfig ¶
func DefaultServiceTestConfig( startBlock uint64, logLevel uint8, policy superwatcher.Policy, ) *superwatcher.Config
func RunService ¶
func RunService( emitter superwatcher.Emitter, engine superwatcher.Engine, ) error
RunService executes the most basic emitter and engine logic, and returns an error from these components.
func RunServiceTestComponents ¶
func RunServiceTestComponents(tc *TestComponents) ( superwatcher.GetStateDataGateway, error, )
RunServiceTestComponents runs the entire service using |components| and |param|. It does so by setting up superwatcher.Emitter and superwatcher.Engine and pass these objects to RunService. StateDataGateway is created within this function and will be returned to caller
Types ¶
type DebugServiceEngine ¶
type DebugServiceEngine struct { ReorgedAt uint64 EmitterFilterRange uint64 // Users can inject these extra debugging functions HandleFuncGoodLog func(*types.Log) error HandleFuncReorgedLog func(*types.Log) error HandleFuncEmitterError func(error) error // contains filtered or unexported fields }
func (*DebugServiceEngine) HandleEmitterError ¶
func (e *DebugServiceEngine) HandleEmitterError(err error) error
func (*DebugServiceEngine) HandleGoodLogs ¶
func (e *DebugServiceEngine) HandleGoodLogs( logs []*types.Log, artifacts []superwatcher.Artifact, ) ( []superwatcher.Artifact, error, )
func (*DebugServiceEngine) HandleReorgedLogs ¶
func (e *DebugServiceEngine) HandleReorgedLogs( logs []*types.Log, artifacts []superwatcher.Artifact, ) ( []superwatcher.Artifact, error, )
func (*DebugServiceEngine) HandleResult ¶
func (e *DebugServiceEngine) HandleResult(result *superwatcher.PollerResult) error
Implements superwatcher.ThinServiceEngine
type TestCase ¶
type TestCase struct { Param reorgsim.Param `json:"param"` Events []reorgsim.ReorgEvent `json:"reorgEvents"` // JSON logs files for initializing reorgSim LogsFiles []string `json:"logFiles"` // If set to true, the emitter will go back due to superwatcher.ErrRecordNotFound DataGatewayFirstRun bool `json:"dataGatewayFirstRun"` // EmitterPoller's poll level Policy superwatcher.Policy `json:"policy"` }
TestCase will be converted into config.Config and reorgsim.Param to create TestComponents
type TestComponents ¶
type TestComponents struct {
// contains filtered or unexported fields
}
TestComponents is used by RunServiceTestComponents to instantiate superwatcher.Emitter and superwatcher.Engine for RunService
func InitTestComponents ¶
func InitTestComponents( conf *superwatcher.Config, serviceEngine superwatcher.ServiceEngine, param reorgsim.Param, events []reorgsim.ReorgEvent, logsFullPaths []string, firstRun bool, ) *TestComponents