Documentation ¶
Overview ¶
Package weavetest provides mocks and functions that makes testing weave functionality easier.
Before adding a new code to this package make sure that it is used in at least two packages. Mocks and helpers that are utilized by only one package should be kept in that package.
Index ¶
- func CommitKVStore(t testing.TB) (db weave.CommitKVStore, cleanup func())
- func Decorate(h weave.Handler, d weave.Decorator) weave.Handler
- func NewCondition() weave.Condition
- func NewKey() crypto.Signer
- func SequenceID(n uint64) []byte
- func SplitTxs(txs []weave.Tx, txPerBlock int) [][]weave.Tx
- type Auth
- type Cron
- type CtxAuth
- type Decorator
- func (d *Decorator) CallCount() int
- func (d *Decorator) Check(ctx weave.Context, db weave.KVStore, tx weave.Tx, next weave.Checker) (*weave.CheckResult, error)
- func (d *Decorator) CheckCallCount() int
- func (d *Decorator) Deliver(ctx weave.Context, db weave.KVStore, tx weave.Tx, next weave.Deliverer) (*weave.DeliverResult, error)
- func (d *Decorator) DeliverCallCount() int
- type Handler
- func (h *Handler) CallCount() int
- func (h *Handler) Check(ctx weave.Context, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error)
- func (h *Handler) CheckCallCount() int
- func (h *Handler) Deliver(ctx weave.Context, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error)
- func (h *Handler) DeliverCallCount() int
- type Msg
- type Strategy
- type Tx
- type WeaveApp
- type WeaveRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitKVStore ¶ added in v0.25.0
func CommitKVStore(t testing.TB) (db weave.CommitKVStore, cleanup func())
CommitKVStore returns a store instance that is using a filesystem backend engine to store the data. This implementation should be used instead of MemStore when you want the exact same storage implementation as the production instance is using.
func NewCondition ¶
NewCondition returns a newly generated unique weave condition. To create a weave address call Address method of returned condition.
func SequenceID ¶
SequenceID returns an ID encoded as if it was generated by the bucket sequence call. This function is helpful for testing sequential event processing and objects creation where the ID of the next saved entity can be determined.
Types ¶
type Auth ¶
type Auth struct { // Signer represents an authentication of a single signer. This is a // convenience attribute when creating an authentication method for a // single signer. // When authenticating all signers declared on this structure are // considered. Signer weave.Condition // Signers represents an authentication of multiple signers. Signers []weave.Condition }
Auth is a mock implementing x.Authenticator interface.
This structure authenticates any of referenced conditions. You can use either Signer or Signers (or both) attributes to reference conditions. This is for the convenience and each time all signers (regardless which attribute) are considered.
type Cron ¶ added in v0.19.0
type Cron struct { Err error // contains filtered or unexported fields }
Cron is a in memory implementation of the ticker and scheduler.
func (*Cron) Schedule ¶ added in v0.19.0
func (c *Cron) Schedule(db weave.KVStore, runAt time.Time, auth []weave.Condition, msg weave.Msg) ([]byte, error)
Schedule implementes weave.Scheduler interface.
func (*Cron) Tick ¶ added in v0.19.0
func (c *Cron) Tick(ctx weave.Context, store weave.CacheableKVStore) weave.TickResult
Tick implementes weave.Ticker interface.
type CtxAuth ¶
type CtxAuth struct { // Key used to set and retrieve conditions from the context. For // convenience only string type keys are allowed. Key string }
CtxAuth is a mock implementing x.Authenticator interface.
This implementation is using context to store and retrieve permissions.
func (*CtxAuth) GetConditions ¶
func (*CtxAuth) HasAddress ¶
type Decorator ¶
type Decorator struct { // CheckErr if set is returned by the Check method before calling // the wrapped handler. CheckErr error // DeliverErr if set is returned by the Deliver method before calling // the wrapped handler. DeliverErr error // contains filtered or unexported fields }
Decorator is a mock implementation of the weave.Decorator interface.
Set CheckErr or DeliverErr to force error response for corresponding method. If error attributes are not set then wrapped handler method is called and its result returned. Each method call is counted. Regardless of the method call result the counter is incremented.
func (*Decorator) CheckCallCount ¶
func (*Decorator) DeliverCallCount ¶
type Handler ¶
type Handler struct { // CheckResult is returned by Check method. CheckResult weave.CheckResult // CheckErr if set is returned by Check method. CheckErr error // DeliverResult is returned by Deliver method. DeliverResult weave.DeliverResult // DeliverErr if set is returned by Deliver method. DeliverErr error // contains filtered or unexported fields }
Handler implements a mock of weave.Handler
Use this handler in your tests. Set XxxResult and XxxErr to control what Xxx method call returns. Each method call is counted.
func (*Handler) CheckCallCount ¶
func (*Handler) DeliverCallCount ¶
type Msg ¶
type Msg struct { // Path returned by the path method, consumed by the router. RoutePath string // Serialized represents the serialized form of this message. Serialized []byte // Err if set is returned by any method call. Err error }
Msg represents a weave message. Message is a request processed by weave within a single transaction.
type Strategy ¶ added in v0.12.1
type Strategy uint8
Strategy defines which functions we call in ProcessAllTxs.
const ( // When set the CheckTx method is being executed for each transaction. ExecCheck Strategy = 1 << iota // When set and running as part of the benchmark, if the CheckTx method // is executed then it is excluded from measurements. Benchmarks are // being paused for the execution of the CheckTx. NoBenchCheck // When set the DeliverTx method is being executed for each // transaction. ExecDeliver ExecCheckAndDeliver = ExecCheck | ExecDeliver )
type Tx ¶
type Tx struct { // Msg is the message that is to be processed by this transaction. Msg weave.Msg // Err if set is returned by any method call. Err error }
Tx represents a weave transaction. Transaction represents a single message that is to be processed within this transaction.
type WeaveApp ¶ added in v0.12.1
WeaveApp is implemented by a weave application. This is the minimal interface required by the WeaveRunner to be able to connect ABCI and weave APIs together.
type WeaveRunner ¶ added in v0.12.1
type WeaveRunner struct {
// contains filtered or unexported fields
}
WeaveRunner provides a translation layer between an ABCI interface and a weave application. It takes care of serializing messages and creating blocks.
func NewWeaveRunner ¶ added in v0.12.1
func NewWeaveRunner(t testing.TB, app abci.Application, chainID string) *WeaveRunner
NewWeaveRunner creates a WeaveRunner instance that can be used to process deliver and check transaction requests using weave API. This runner expects all operations to succeed. Any error results in test failure.
func (*WeaveRunner) CheckTx ¶ added in v0.12.1
func (w *WeaveRunner) CheckTx(tx weave.Tx) error
CheckTx translates given weave transaction into ABCI interface and executes.
func (*WeaveRunner) DeliverTx ¶ added in v0.12.1
func (w *WeaveRunner) DeliverTx(tx weave.Tx) error
DeliverTx translates given weave transaction into ABCI interface and executes.
func (*WeaveRunner) InBlock ¶ added in v0.12.1
func (w *WeaveRunner) InBlock(executeTx func(WeaveApp) error) bool
InBlock begins a block and runs given function. All transactions executed withing given function are part of newly created block. Upon success the block is finished and changes committed. InBlock returns true if the application state was modified. It returns false if creating new block did not modify the state.
Any failure is ending the test instantly.
func (*WeaveRunner) InitChain ¶ added in v0.12.1
func (w *WeaveRunner) InitChain(genesis interface{})
InitChain serialize to JSON given genesis and loads it. Loading a genesis is causing a block creation.
func (*WeaveRunner) ProcessAllTxs ¶ added in v0.12.1
func (w *WeaveRunner) ProcessAllTxs(blocks [][]weave.Tx, st Strategy)
ProcessAllTxs will run all included txs, split into blocksize. It will Fail() if any tx returns an error, or if at any block, the appHash does not change (if should change, otherwise, require it stable)