nop

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 4 Imported by: 0

README

Nop Bus

Nop bus provides a no-operation producer and consumer mostly for testing.

Documentation

Index

Constants

View Source
const (
	// Init_err returns err on NewConsumer
	InitErr = "init_err"
	MsgErr  = "msg_err" // returns err on Consumer.Msg() call.
	//Err = "err" //  every method returns an error
	MsgDone    = "msg_done"     // returns a nil task message done=true on Consumer.Msg() call.
	MsgMsgDone = "msg_msg_done" // returns a non-nil task message and done=true Consumer.Msg() call.
	StopErr    = "stop_err"     // returns err on Stop() method call
)
View Source
const (
	Send_err = "send_err"
)

Variables

View Source
var FakeMsg = []byte(`{"type":"test","info":"test-info","created":"2017-01-01T00:00:01Z"}`)

FakeMsg can be set to control the returned Msg() msg value.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {

	// Mock can be for mocking Consumer
	// see const above for supported values
	// Supported Values:
	// - "init_err" - returns err on NewConsumer
	// - "err" - every method returns an error
	// - "msg_err" - returns err on Consumer.Msg() call.
	// - "msg_done" - returns a nil task message done=true on Consumer.Msg() call.
	// - "msg_msg_done" - returns a non-nil task message and done=true Consumer.Msg() call.
	// - "stop_err" - returns err on Stop() method call
	Mock  string
	Stats info.Consumer
}

Consumer is a no-operation consumer. It does not do anything and is useful for mocking.

func NewConsumer

func NewConsumer(mock string) (*Consumer, error)

NewConsumer returns a nop (no-operation) Consumer. Will return *Consumer == nil and err != nil if mock == "init_err".

func (*Consumer) Info added in v0.2.0

func (c *Consumer) Info() info.Consumer

func (*Consumer) Msg

func (c *Consumer) Msg() (msg []byte, done bool, err error)

Msg will always return a fake task message unless err != nil or Mock == "msg_done".

func (*Consumer) Stop

func (c *Consumer) Stop() error

Stop is a mock consumer Stop method.

type Producer

type Producer struct {
	// Mock can be set in order to
	// mock various return scenarios.
	//
	// Supported Values:
	// - "init_err" - returns err on NewProducer
	// - "err" - every method returns an error
	// - "send_err" - returns err when Producer.Send() is called.
	// - "stop_err" - returns err on Stop() method call
	Mock     string
	Messages map[string][]string // [topic]Messages
	Stats    info.Producer
	// contains filtered or unexported fields
}

Producer is a no-operation consumer. It does not do anything and is useful for mocking.

func NewProducer

func NewProducer(mock string) (*Producer, error)

NewProducer returns a nop (no-operation) Producer. Will return *Producer == nil and err != nil if mock == "init_err".

func (*Producer) Contains added in v0.2.0

func (p *Producer) Contains(topic string, msg []byte) bool

func (*Producer) Info added in v0.2.0

func (c *Producer) Info() info.Producer

func (*Producer) Send

func (p *Producer) Send(topic string, msg []byte) error

func (*Producer) Stop

func (p *Producer) Stop() error

Stop is a mock producer Stop method.

Jump to

Keyboard shortcuts

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