Documentation ¶
Overview ¶
Package eventtools provides testing tools for working with the go.infratographer.com/x/events package.
Index ¶
- Variables
- type MockConnection
- func (c *MockConnection) PublishAuthRelationshipRequest(_ context.Context, topic string, message events.AuthRelationshipRequest) (events.Message[events.AuthRelationshipResponse], error)
- func (c *MockConnection) PublishChange(_ context.Context, topic string, message events.ChangeMessage) (events.Message[events.ChangeMessage], error)
- func (c *MockConnection) PublishEvent(_ context.Context, topic string, message events.EventMessage) (events.Message[events.EventMessage], error)
- func (c *MockConnection) Shutdown(_ context.Context) error
- func (c *MockConnection) Source() any
- func (c *MockConnection) SubscribeAuthRelationshipRequests(_ context.Context, topic string) (...)
- func (c *MockConnection) SubscribeChanges(_ context.Context, topic string) (<-chan events.Message[events.ChangeMessage], error)
- func (c *MockConnection) SubscribeEvents(_ context.Context, topic string) (<-chan events.Message[events.EventMessage], error)
- type MockMessage
- func (m *MockMessage[T]) Ack() error
- func (m *MockMessage[T]) Connection() events.Connection
- func (m *MockMessage[T]) Deliveries() uint64
- func (m *MockMessage[T]) Error() error
- func (m *MockMessage[T]) ID() string
- func (m *MockMessage[T]) Message() T
- func (m *MockMessage[T]) Nak(delay time.Duration) error
- func (m *MockMessage[T]) ReplyAuthRelationshipRequest(_ context.Context, message events.AuthRelationshipResponse) (events.Message[events.AuthRelationshipResponse], error)
- func (m *MockMessage[T]) Source() any
- func (m *MockMessage[T]) Term() error
- func (m *MockMessage[T]) Timestamp() time.Time
- func (m *MockMessage[T]) Topic() string
- type TestNats
Constants ¶
This section is empty.
Variables ¶
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
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
func (c *MockConnection) PublishChange(_ context.Context, topic string, message events.ChangeMessage) (events.Message[events.ChangeMessage], error)
PublishChange implements events.Connection
func (*MockConnection) PublishEvent ¶ added in v0.3.5
func (c *MockConnection) PublishEvent(_ context.Context, topic string, message events.EventMessage) (events.Message[events.EventMessage], error)
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
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 ¶
NewNatsServer returns a simple NATs server that starts and stores it's data in a tmp dir
func (*TestNats) SetConsumerSampleFrequency ¶ added in v0.3.2
SetConsumerSampleFrequency ensures the ack sample frequency is set to the provided frequency.
func (*TestNats) WaitForAck ¶ added in v0.3.2
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.