mediator

package
v0.0.0-...-2a922c4 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mediator

type Mediator interface {
	Register(subscriber Subscriber)
	Unregister(subscriber Subscriber)
	Publish(ctx context.Context, message Message)
	Start(ctx context.Context)
	SubscriberCount() int
}

func New

func New(logger *slog.Logger) Mediator

type MediatorMock

type MediatorMock struct {
	// PublishFunc mocks the Publish method.
	PublishFunc func(ctx context.Context, message Message)

	// RegisterFunc mocks the Register method.
	RegisterFunc func(subscriber Subscriber)

	// StartFunc mocks the Start method.
	StartFunc func(ctx context.Context)

	// SubscriberCountFunc mocks the SubscriberCount method.
	SubscriberCountFunc func() int

	// UnregisterFunc mocks the Unregister method.
	UnregisterFunc func(subscriber Subscriber)
	// contains filtered or unexported fields
}

MediatorMock is a mock implementation of Mediator.

func TestSomethingThatUsesMediator(t *testing.T) {

	// make and configure a mocked Mediator
	mockedMediator := &MediatorMock{
		PublishFunc: func(ctx context.Context, message Message)  {
			panic("mock out the Publish method")
		},
		RegisterFunc: func(subscriber Subscriber)  {
			panic("mock out the Register method")
		},
		StartFunc: func(ctx context.Context)  {
			panic("mock out the Start method")
		},
		SubscriberCountFunc: func() int {
			panic("mock out the SubscriberCount method")
		},
		UnregisterFunc: func(subscriber Subscriber)  {
			panic("mock out the Unregister method")
		},
	}

	// use mockedMediator in code that requires Mediator
	// and then make assertions.

}

func (*MediatorMock) Publish

func (mock *MediatorMock) Publish(ctx context.Context, message Message)

Publish calls PublishFunc.

func (*MediatorMock) PublishCalls

func (mock *MediatorMock) PublishCalls() []struct {
	Ctx     context.Context
	Message Message
}

PublishCalls gets all the calls that were made to Publish. Check the length with:

len(mockedMediator.PublishCalls())

func (*MediatorMock) Register

func (mock *MediatorMock) Register(subscriber Subscriber)

Register calls RegisterFunc.

func (*MediatorMock) RegisterCalls

func (mock *MediatorMock) RegisterCalls() []struct {
	Subscriber Subscriber
}

RegisterCalls gets all the calls that were made to Register. Check the length with:

len(mockedMediator.RegisterCalls())

func (*MediatorMock) Start

func (mock *MediatorMock) Start(ctx context.Context)

Start calls StartFunc.

func (*MediatorMock) StartCalls

func (mock *MediatorMock) StartCalls() []struct {
	Ctx context.Context
}

StartCalls gets all the calls that were made to Start. Check the length with:

len(mockedMediator.StartCalls())

func (*MediatorMock) SubscriberCount

func (mock *MediatorMock) SubscriberCount() int

SubscriberCount calls SubscriberCountFunc.

func (*MediatorMock) SubscriberCountCalls

func (mock *MediatorMock) SubscriberCountCalls() []struct {
}

SubscriberCountCalls gets all the calls that were made to SubscriberCount. Check the length with:

len(mockedMediator.SubscriberCountCalls())

func (*MediatorMock) Unregister

func (mock *MediatorMock) Unregister(subscriber Subscriber)

Unregister calls UnregisterFunc.

func (*MediatorMock) UnregisterCalls

func (mock *MediatorMock) UnregisterCalls() []struct {
	Subscriber Subscriber
}

UnregisterCalls gets all the calls that were made to Unregister. Check the length with:

len(mockedMediator.UnregisterCalls())

type Message

type Message interface {
	ID() string
	Type() string
	Data() []byte
	Tenant() string
	Retry() int
	Timestamp() time.Time
	Context() context.Context
}

func NewMessage

func NewMessage(ctx context.Context, id, name, tenant string, data []byte) Message

type Subscriber

type Subscriber interface {
	ID() string
	Tenants() []string
	Mailbox() chan Message
	Handle(m Message) bool
}

func NewSubscriber

func NewSubscriber(tenants []string) Subscriber

Jump to

Keyboard shortcuts

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