mock

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 5 Imported by: 4

README

Mock dialect

A in-memory mocking dialect. This dialect is the main dialect used by commander to preform unit tests. The dialect could also be used as a bridge between protocols that have no official dialect support.

Getting started

No initial configurations are required to setup the mock dialect. Simply construct a new dialect and your good to go.

dialect := mock.NewDialect()
// ...

Documentation

Index

Constants

View Source
const (
	// DebugEnv os debug env key
	DebugEnv = "DEBUG"
)

Variables

This section is empty.

Functions

func NewDialect

func NewDialect() types.Dialect

NewDialect constructs a new in-memory mocking dialect

Types

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer a message consumer

func (*Consumer) Close

func (consumer *Consumer) Close() error

Close closes the kafka consumer, all topic subscriptions and event channels.

func (*Consumer) Emit added in v0.3.0

func (consumer *Consumer) Emit(message *types.Message)

Emit emits the given message to the subscribed consumers

func (*Consumer) Subscribe

func (consumer *Consumer) Subscribe(topics ...types.Topic) (<-chan *types.Message, error)

Subscribe creates a new topic subscription that will receive messages consumed by the consumer of the given topic. This method will return a message channel and a close function. Once a message is consumed should the marked channel be called. Pass a nil for a successful consume and a error if a error occurred during processing.

func (*Consumer) Unsubscribe

func (consumer *Consumer) Unsubscribe(sub <-chan *types.Message) error

Unsubscribe unsubscribes the given channel subscription from the given topic. A boolean is returned that represents if the channel successfully got unsubscribed.

type Dialect

type Dialect struct {
	// contains filtered or unexported fields
}

Dialect a in-memory mocking dialect

func (*Dialect) Close

func (dialect *Dialect) Close() error

Close awaits till the consumer(s) and producer(s) of the given dialect are closed. If an error is returned is the closing aborted and the error returned to the user.

func (*Dialect) Consumer

func (dialect *Dialect) Consumer() types.Consumer

Consumer returns the dialect consumer

func (*Dialect) Healthy

func (dialect *Dialect) Healthy() bool

Healthy when called should it check if the dialect's consumer/producer are healthy and up and running. This method could be called to check if the service is up and running. The user should implement the health check

func (*Dialect) Open

func (dialect *Dialect) Open([]types.Topic) error

Open notifies a dialect to open the dialect. No further topic assignments should be made.

func (*Dialect) Producer

func (dialect *Dialect) Producer() types.Producer

Producer returns the dialect producer

type Producer

type Producer struct {
	// contains filtered or unexported fields
}

Producer a message producer

func (*Producer) Close

func (producer *Producer) Close() error

Close closes the producer

func (*Producer) Publish

func (producer *Producer) Publish(message *types.Message) error

Publish produces a message to the given topic

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription mock message subscription

type SubscriptionCollection

type SubscriptionCollection struct {
	// contains filtered or unexported fields
}

SubscriptionCollection represents a collection of subscriptions

func NewTopic

func NewTopic() *SubscriptionCollection

NewTopic constructs a new subscription collection for a topic

Jump to

Keyboard shortcuts

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