eventtools

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package eventtools provides testing tools for working with the go.infratographer.com/x/events package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Prefix to use when creating the nats server jetstream subjects
	Prefix = "com.infratographer.testing"
	// Subjects to create in jetstream
	Subjects = []string{Prefix + ".events.>", Prefix + ".changes.>"}

	// ErrNack is returned if a nack is received instead of an ack
	ErrNack = errors.New("nack received")
	// ErrNoAck is returned when no ack is received and the timeout was hit
	ErrNoAck = errors.New("no ack received")
)

Functions

This section is empty.

Types

type MockConnection added in v0.3.5

type MockConnection struct {
	mock.Mock
}

MockConnection implements events.Connection

func (*MockConnection) PublishAuthRelationshipRequest added in v0.3.5

func (c *MockConnection) PublishAuthRelationshipRequest(_ context.Context, topic string, message events.AuthRelationshipRequest) (events.Message[events.AuthRelationshipResponse], error)

PublishAuthRelationshipRequest implements events.Connection

func (*MockConnection) PublishChange added in v0.3.5

PublishChange implements events.Connection

func (*MockConnection) PublishEvent added in v0.3.5

PublishEvent implements events.Connection

func (*MockConnection) Shutdown added in v0.3.5

func (c *MockConnection) Shutdown(_ context.Context) error

Shutdown implements events.Connection

func (*MockConnection) Source added in v0.3.5

func (c *MockConnection) Source() any

Source implements events.Connection

func (*MockConnection) SubscribeAuthRelationshipRequests added in v0.3.5

func (c *MockConnection) SubscribeAuthRelationshipRequests(_ context.Context, topic string) (<-chan events.Request[events.AuthRelationshipRequest, events.AuthRelationshipResponse], error)

SubscribeAuthRelationshipRequests implements events.Connection

func (*MockConnection) SubscribeChanges added in v0.3.5

func (c *MockConnection) SubscribeChanges(_ context.Context, topic string) (<-chan events.Message[events.ChangeMessage], error)

SubscribeChanges implements events.Connection

func (*MockConnection) SubscribeEvents added in v0.3.5

func (c *MockConnection) SubscribeEvents(_ context.Context, topic string) (<-chan events.Message[events.EventMessage], error)

SubscribeEvents implements events.Connection

type MockMessage added in v0.3.5

type MockMessage[T any] struct {
	mock.Mock
}

MockMessage implements events.Message.

func (*MockMessage[T]) Ack added in v0.3.5

func (m *MockMessage[T]) Ack() error

Ack implements events.Message.

func (*MockMessage[T]) Connection added in v0.3.5

func (m *MockMessage[T]) Connection() events.Connection

Connection implements events.Message.

func (*MockMessage[T]) Deliveries added in v0.3.5

func (m *MockMessage[T]) Deliveries() uint64

Deliveries implements events.Message.

func (*MockMessage[T]) Error added in v0.3.5

func (m *MockMessage[T]) Error() error

Error implements events.Message.

func (*MockMessage[T]) ID added in v0.3.5

func (m *MockMessage[T]) ID() string

ID implements events.Message.

func (*MockMessage[T]) Message added in v0.3.5

func (m *MockMessage[T]) Message() T

Message implements events.Message.

func (*MockMessage[T]) Nak added in v0.3.5

func (m *MockMessage[T]) Nak(delay time.Duration) error

Nak implements events.Message.

func (*MockMessage[T]) ReplyAuthRelationshipRequest added in v0.3.5

func (m *MockMessage[T]) ReplyAuthRelationshipRequest(_ context.Context, message events.AuthRelationshipResponse) (events.Message[events.AuthRelationshipResponse], error)

ReplyAuthRelationshipRequest implements events.Message.

func (*MockMessage[T]) Source added in v0.3.5

func (m *MockMessage[T]) Source() any

Source implements events.Message.

func (*MockMessage[T]) Term added in v0.3.5

func (m *MockMessage[T]) Term() error

Term implements events.Message.

func (*MockMessage[T]) Timestamp added in v0.3.5

func (m *MockMessage[T]) Timestamp() time.Time

Timestamp implements events.Message.

func (*MockMessage[T]) Topic added in v0.3.5

func (m *MockMessage[T]) Topic() string

Topic implements events.Message.

type TestNats added in v0.3.2

type TestNats struct {
	Server    *server.Server
	Conn      *nats.Conn
	JetStream nats.JetStreamContext
	Config    events.Config
}

TestNats maintains the nats environment

func NewNatsServer

func NewNatsServer() (*TestNats, error)

NewNatsServer returns a simple NATs server that starts and stores it's data in a tmp dir

func (*TestNats) Close added in v0.3.2

func (s *TestNats) Close()

Close closes the connection

func (*TestNats) SetConsumerSampleFrequency added in v0.3.2

func (s *TestNats) SetConsumerSampleFrequency(consumer, frequency string) error

SetConsumerSampleFrequency ensures the ack sample frequency is set to the provided frequency.

func (*TestNats) WaitForAck added in v0.3.2

func (s *TestNats) WaitForAck(consumer string, timeout time.Duration) error

WaitForAck waits for an ack message to be received, returns error if Nack or timeout is hit. To ensure Acks are received, ensure you have set ManualAck, AckExplicit and Durable subscriber options. As well as SetConsumerSampleFrequency is set to 100.

Jump to

Keyboard shortcuts

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