-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mike Mason <[email protected]>
- Loading branch information
Showing
3 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package eventtools | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stretchr/testify/mock" | ||
|
||
"go.infratographer.com/x/events" | ||
) | ||
|
||
var _ events.Connection = (*MockConnection)(nil) | ||
|
||
// MockConnection implements events.Connection | ||
type MockConnection struct { | ||
mock.Mock | ||
} | ||
|
||
// Close implements events.Connection | ||
func (c *MockConnection) Close(_ context.Context) error { | ||
args := c.Called() | ||
|
||
return args.Error(0) | ||
} | ||
|
||
// Publish implements events.Connection | ||
func (c *MockConnection) Publish(_ context.Context, topic string, message any) (events.Message[any], error) { | ||
args := c.Called(topic, message) | ||
|
||
return args.Get(0).(events.Message[any]), args.Error(1) | ||
} | ||
|
||
// PublishAuthRelationshipRequest implements events.Connection | ||
func (c *MockConnection) PublishAuthRelationshipRequest(_ context.Context, topic string, message events.AuthRelationshipRequest) (events.Message[events.AuthRelationshipResponse], error) { | ||
args := c.Called(topic, message) | ||
|
||
return args.Get(0).(events.Message[events.AuthRelationshipResponse]), args.Error(1) | ||
} | ||
|
||
// PublishChange implements events.Connection | ||
func (c *MockConnection) PublishChange(_ context.Context, topic string, message events.ChangeMessage) (events.Message[events.ChangeMessage], error) { | ||
args := c.Called(topic, message) | ||
|
||
return args.Get(0).(events.Message[events.ChangeMessage]), args.Error(1) | ||
} | ||
|
||
// PublishEvent implements events.Connection | ||
func (c *MockConnection) PublishEvent(_ context.Context, topic string, message events.EventMessage) (events.Message[events.EventMessage], error) { | ||
args := c.Called(topic, message) | ||
|
||
return args.Get(0).(events.Message[events.EventMessage]), args.Error(1) | ||
} | ||
|
||
// Source implements events.Connection | ||
func (c *MockConnection) Source() any { | ||
args := c.Called() | ||
|
||
return args.Error(0) | ||
} | ||
|
||
// Subscribe implements events.Connection | ||
func (c *MockConnection) Subscribe(_ context.Context, topic string) (<-chan events.Message[any], error) { | ||
args := c.Called(topic) | ||
|
||
return args.Get(0).(<-chan events.Message[any]), args.Error(1) | ||
} | ||
|
||
// SubscribeAuthRelationshipRequests implements events.Connection | ||
func (c *MockConnection) SubscribeAuthRelationshipRequests(_ context.Context, topic string) (<-chan events.Message[events.AuthRelationshipRequest], error) { | ||
args := c.Called(topic) | ||
|
||
return args.Get(0).(<-chan events.Message[events.AuthRelationshipRequest]), args.Error(1) | ||
} | ||
|
||
// SubscribeChanges implements events.Connection | ||
func (c *MockConnection) SubscribeChanges(_ context.Context, topic string) (<-chan events.Message[events.ChangeMessage], error) { | ||
args := c.Called(topic) | ||
|
||
return args.Get(0).(<-chan events.Message[events.ChangeMessage]), args.Error(1) | ||
} | ||
|
||
// SubscribeEvents implements events.Connection | ||
func (c *MockConnection) SubscribeEvents(_ context.Context, topic string) (<-chan events.Message[events.EventMessage], error) { | ||
args := c.Called(topic) | ||
|
||
return args.Get(0).(<-chan events.Message[events.EventMessage]), args.Error(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package eventtools | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/stretchr/testify/mock" | ||
|
||
"go.infratographer.com/x/events" | ||
) | ||
|
||
var _ events.Message[any] = (*MockMessage[interface{}])(nil) | ||
|
||
// MockMessage implements events.Message. | ||
type MockMessage[T any] struct { | ||
mock.Mock | ||
} | ||
|
||
// Connection implements events.Message. | ||
func (m *MockMessage[T]) Connection() events.Connection { | ||
args := m.Called() | ||
|
||
return args.Get(0).(events.Connection) | ||
} | ||
|
||
// ID implements events.Message. | ||
func (m *MockMessage[T]) ID() string { | ||
args := m.Called() | ||
|
||
return args.String(0) | ||
} | ||
|
||
// Topic implements events.Message. | ||
func (m *MockMessage[T]) Topic() string { | ||
args := m.Called() | ||
|
||
return args.String(0) | ||
} | ||
|
||
// Message implements events.Message. | ||
func (m *MockMessage[T]) Message() T { | ||
args := m.Called() | ||
|
||
return args.Get(0).(T) | ||
} | ||
|
||
// Ack implements events.Message. | ||
func (m *MockMessage[T]) Ack() error { | ||
args := m.Called() | ||
|
||
return args.Error(0) | ||
} | ||
|
||
// Nak implements events.Message. | ||
func (m *MockMessage[T]) Nak(delay time.Duration) error { | ||
args := m.Called(delay) | ||
|
||
return args.Error(0) | ||
} | ||
|
||
// Term implements events.Message. | ||
func (m *MockMessage[T]) Term() error { | ||
args := m.Called() | ||
|
||
return args.Error(0) | ||
} | ||
|
||
// Timestamp implements events.Message. | ||
func (m *MockMessage[T]) Timestamp() time.Time { | ||
args := m.Called() | ||
|
||
return args.Get(0).(time.Time) | ||
} | ||
|
||
// Deliveries implements events.Message. | ||
func (m *MockMessage[T]) Deliveries() uint64 { | ||
args := m.Called() | ||
|
||
return args.Get(0).(uint64) | ||
} | ||
|
||
// Error implements events.Message. | ||
func (m *MockMessage[T]) Error() error { | ||
args := m.Called() | ||
|
||
return args.Error(0) | ||
} | ||
|
||
// ReplyAuthRelationshipRequest implements events.Message. | ||
func (m *MockMessage[T]) ReplyAuthRelationshipRequest(_ context.Context, message events.AuthRelationshipResponse) (events.Message[events.AuthRelationshipResponse], error) { | ||
args := m.Called(message) | ||
|
||
return args.Get(0).(events.Message[events.AuthRelationshipResponse]), args.Error(1) | ||
} | ||
|
||
// Source implements events.Message. | ||
func (m *MockMessage[T]) Source() any { | ||
args := m.Called() | ||
|
||
return args.Error(0) | ||
} |