Documentation
¶
Index ¶
- func NewAgentTopic(t *testing.T) *pubsub.Topic[agent.AgentEvent]
- func NewDockerTopic(t *testing.T) *pubsub.Topic[dockerevents.DockerEvent]
- type AgentRecorder
- type RegistryMock
- func (mock *RegistryMock) Add(entry agent.Entry) error
- func (mock *RegistryMock) AddCalls() []struct{ ... }
- func (mock *RegistryMock) EvictByContainerID(containerID string) error
- func (mock *RegistryMock) EvictByContainerIDCalls() []struct{ ... }
- func (mock *RegistryMock) LookupByContainerID(containerID string) (*agent.Entry, error)
- func (mock *RegistryMock) LookupByContainerIDCalls() []struct{ ... }
- func (mock *RegistryMock) Snapshot() ([]agent.Entry, error)
- func (mock *RegistryMock) SnapshotCalls() []struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAgentTopic ¶
NewAgentTopic constructs a real *pubsub.Topic[AgentEvent] for tests and registers cleanup. The pipe is the production transport — tests drive real Publish/Subscribe rather than a mock, since the pipe is generic (moq cannot mock it) and cheap in-memory.
func NewDockerTopic ¶
func NewDockerTopic(t *testing.T) *pubsub.Topic[dockerevents.DockerEvent]
NewDockerTopic constructs a real *pubsub.Topic[DockerEvent] for tests and registers cleanup.
Types ¶
type AgentRecorder ¶
type AgentRecorder struct {
// contains filtered or unexported fields
}
AgentRecorder is a thread-safe recording subscriber for AgentEvents. It captures every delivered payload so tests can assert the discriminated (Type, Action, Reason) the producer published. Delivery runs on the topic's own drain goroutine, so the mutex guards the slice against the test goroutine reading concurrently.
func DialerWithTopic ¶
DialerWithTopic builds a *Dialer wired to a fresh agent topic + the supplied registry, and returns it alongside a recorder already subscribed to the topic. Used by the driveRegister / dispatchAgentEvents tests that drive the dialer's publish paths directly.
func RecordAgent ¶
func RecordAgent(topic *pubsub.Topic[agent.AgentEvent]) *AgentRecorder
RecordAgent subscribes a recorder to the topic and returns it.
func (*AgentRecorder) FirstWith ¶
func (r *AgentRecorder) FirstWith(typ agent.EventType, action agent.Action) (agent.AgentEvent, bool)
FirstWith returns the first recorded event matching (type, action) and whether one was found.
func (*AgentRecorder) WithAction ¶
func (r *AgentRecorder) WithAction(typ agent.EventType, action agent.Action) []agent.AgentEvent
WithAction returns every recorded event matching (type, action), in arrival order.
type RegistryMock ¶
type RegistryMock struct {
// AddFunc mocks the Add method.
AddFunc func(entry agent.Entry) error
// EvictByContainerIDFunc mocks the EvictByContainerID method.
EvictByContainerIDFunc func(containerID string) error
// LookupByContainerIDFunc mocks the LookupByContainerID method.
LookupByContainerIDFunc func(containerID string) (*agent.Entry, error)
// SnapshotFunc mocks the Snapshot method.
SnapshotFunc func() ([]agent.Entry, error)
// contains filtered or unexported fields
}
RegistryMock is a mock implementation of agent.Registry.
func TestSomethingThatUsesRegistry(t *testing.T) {
// make and configure a mocked agent.Registry
mockedRegistry := &RegistryMock{
AddFunc: func(entry agent.Entry) error {
panic("mock out the Add method")
},
EvictByContainerIDFunc: func(containerID string) error {
panic("mock out the EvictByContainerID method")
},
LookupByContainerIDFunc: func(containerID string) (*agent.Entry, error) {
panic("mock out the LookupByContainerID method")
},
SnapshotFunc: func() ([]agent.Entry, error) {
panic("mock out the Snapshot method")
},
}
// use mockedRegistry in code that requires agent.Registry
// and then make assertions.
}
func (*RegistryMock) Add ¶
func (mock *RegistryMock) Add(entry agent.Entry) error
Add calls AddFunc.
func (*RegistryMock) AddCalls ¶
func (mock *RegistryMock) AddCalls() []struct { Entry agent.Entry }
AddCalls gets all the calls that were made to Add. Check the length with:
len(mockedRegistry.AddCalls())
func (*RegistryMock) EvictByContainerID ¶
func (mock *RegistryMock) EvictByContainerID(containerID string) error
EvictByContainerID calls EvictByContainerIDFunc.
func (*RegistryMock) EvictByContainerIDCalls ¶
func (mock *RegistryMock) EvictByContainerIDCalls() []struct { ContainerID string }
EvictByContainerIDCalls gets all the calls that were made to EvictByContainerID. Check the length with:
len(mockedRegistry.EvictByContainerIDCalls())
func (*RegistryMock) LookupByContainerID ¶
func (mock *RegistryMock) LookupByContainerID(containerID string) (*agent.Entry, error)
LookupByContainerID calls LookupByContainerIDFunc.
func (*RegistryMock) LookupByContainerIDCalls ¶
func (mock *RegistryMock) LookupByContainerIDCalls() []struct { ContainerID string }
LookupByContainerIDCalls gets all the calls that were made to LookupByContainerID. Check the length with:
len(mockedRegistry.LookupByContainerIDCalls())
func (*RegistryMock) Snapshot ¶
func (mock *RegistryMock) Snapshot() ([]agent.Entry, error)
Snapshot calls SnapshotFunc.
func (*RegistryMock) SnapshotCalls ¶
func (mock *RegistryMock) SnapshotCalls() []struct { }
SnapshotCalls gets all the calls that were made to Snapshot. Check the length with:
len(mockedRegistry.SnapshotCalls())