weavetest

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: Apache-2.0 Imports: 19 Imported by: 2

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

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 Decorate

func Decorate(h weave.Handler, d weave.Decorator) weave.Handler

func NewCondition

func NewCondition() weave.Condition

NewCondition returns a newly generated unique weave condition. To create a weave address call Address method of returned condition.

func NewKey

func NewKey() crypto.Signer

NewKey returns a newly generated unique private key.

func SequenceID

func SequenceID(n uint64) []byte

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.

func SplitTxs added in v0.12.1

func SplitTxs(txs []weave.Tx, txPerBlock int) [][]weave.Tx

SplitTxs will break one slice of transactions into many slices, one per block. It will fill up to txPerBlock txs in each block The last block may have less, if there is not enough for a full block

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.

func (*Auth) GetConditions

func (a *Auth) GetConditions(weave.Context) []weave.Condition

func (*Auth) HasAddress

func (a *Auth) HasAddress(ctx weave.Context, addr weave.Address) bool

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) Delete added in v0.19.0

func (c *Cron) Delete(db weave.KVStore, taskID []byte) error

Delete implementes weave.Scheduler interface.

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 (a *CtxAuth) GetConditions(ctx weave.Context) []weave.Condition

func (*CtxAuth) HasAddress

func (a *CtxAuth) HasAddress(ctx weave.Context, addr weave.Address) bool

func (*CtxAuth) SetConditions

func (a *CtxAuth) SetConditions(ctx weave.Context, permissions ...weave.Condition) weave.Context

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) CallCount

func (d *Decorator) CallCount() int

func (*Decorator) Check

func (d *Decorator) Check(ctx weave.Context, db weave.KVStore, tx weave.Tx, next weave.Checker) (*weave.CheckResult, error)

func (*Decorator) CheckCallCount

func (d *Decorator) CheckCallCount() int

func (*Decorator) Deliver

func (d *Decorator) Deliver(ctx weave.Context, db weave.KVStore, tx weave.Tx, next weave.Deliverer) (*weave.DeliverResult, error)

func (*Decorator) DeliverCallCount

func (d *Decorator) DeliverCallCount() int

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) CallCount

func (h *Handler) CallCount() int

func (*Handler) Check

func (h *Handler) Check(ctx weave.Context, db weave.KVStore, tx weave.Tx) (*weave.CheckResult, error)

func (*Handler) CheckCallCount

func (h *Handler) CheckCallCount() int

func (*Handler) Deliver

func (h *Handler) Deliver(ctx weave.Context, db weave.KVStore, tx weave.Tx) (*weave.DeliverResult, error)

func (*Handler) DeliverCallCount

func (h *Handler) DeliverCallCount() int

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.

func (*Msg) Marshal

func (m *Msg) Marshal() ([]byte, error)

func (*Msg) Path

func (m *Msg) Path() string

func (*Msg) Unmarshal

func (m *Msg) Unmarshal(b []byte) error

func (*Msg) Validate added in v0.14.0

func (m *Msg) Validate() error

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
)

func (Strategy) Has added in v0.12.1

func (s Strategy) Has(other Strategy) bool

Has return true if this strategy contains given one - given strategy is a subset of this one.

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.

func (*Tx) GetMsg

func (tx *Tx) GetMsg() (weave.Msg, error)

func (*Tx) Marshal

func (tx *Tx) Marshal() ([]byte, error)

func (*Tx) Unmarshal

func (tx *Tx) Unmarshal(raw []byte) error

type WeaveApp added in v0.12.1

type WeaveApp interface {
	DeliverTx(weave.Tx) error
	CheckTx(weave.Tx) error
}

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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