weavetest

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

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 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.

Types

type Auth

type Auth struct {
	// Signer represents an authentication of a single signer. This is a
	// convinience 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 convinience 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 CtxAuth

type CtxAuth struct {
	// Key used to set and retrieve conditions from the context. For
	// convinience 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

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

Jump to

Keyboard shortcuts

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