akira

package module
v0.0.0-...-8754167 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: MPL-2.0 Imports: 3 Imported by: 4

README

akira

Akira provides a complete go-nats interface with a mock connection for testing.

How to use it

You can use it like:

fc = akira.NewFakeConnector()

// Create a fake connector
xfc := fc.(*akira.FakeConnector)

// Subscribe to a specific event stream
fc.Subscribe("environment.get", func(m *nats.Msg){ println("Hello world!")})
fc.Publish("environment.get", "{...}")

// You can get a history of events accessing xfc.Events

Running Tests

make lint
make test

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

Moreover, if your pull request contains patches or features, you must include relevant unit tests.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, this project is maintained under the Semantic Versioning guidelines.

Code and documentation copyright since 2015 r3labs.io authors.

Code released under the Mozilla Public License Version 2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector interface {
	Close()
	Request(subj string, data []byte, timeout time.Duration) (*nats.Msg, error)
	Publish(subj string, data []byte) error
	Subscribe(subj string, cb nats.MsgHandler) (*nats.Subscription, error)
	QueueSubscribe(subj string, queue string, cb nats.MsgHandler) (*nats.Subscription, error)
}

Connector provides an interface to NATS. This allows the service to be mocked so an actual NATS instance isn't required for unit testing.

func NewFakeConnector

func NewFakeConnector() Connector

NewFakeConnector : Returns a new fake connector

type FakeConnector

type FakeConnector struct {
	Events   map[string][]*nats.Msg
	Handlers map[string]nats.MsgHandler
	// contains filtered or unexported fields
}

FakeConnector : A fake nats connector for testing nats handlers

func (*FakeConnector) Close

func (f *FakeConnector) Close()

Close : Resets all handlers and events

func (*FakeConnector) Publish

func (f *FakeConnector) Publish(subj string, data []byte) error

Publish : Publish an event

func (*FakeConnector) QueueSubscribe

func (f *FakeConnector) QueueSubscribe(subj string, queue string, cb nats.MsgHandler) (*nats.Subscription, error)

QueueSubscribe : Subscribe to an event stream

func (*FakeConnector) Request

func (f *FakeConnector) Request(subj string, data []byte, timeout time.Duration) (*nats.Msg, error)

Request : Make a request

func (*FakeConnector) Reset

func (f *FakeConnector) Reset()

Reset : resets all handlers and events

func (*FakeConnector) ResetEvents

func (f *FakeConnector) ResetEvents()

ResetEvents : Resets cache of collected events

func (*FakeConnector) ResetHandlers

func (f *FakeConnector) ResetHandlers()

ResetHandlers : Resets all handlers

func (*FakeConnector) Subscribe

func (f *FakeConnector) Subscribe(subj string, cb nats.MsgHandler) (*nats.Subscription, error)

Subscribe : Subscribe to an event stream

Jump to

Keyboard shortcuts

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