Skip to content

Commit 6a0f8f7

Browse files
committed
test(watcher): event dispatch with mock Docker client, per-project serialization, label filtering
1 parent 0d4ed56 commit 6a0f8f7

2 files changed

Lines changed: 488 additions & 3 deletions

File tree

internal/watcher/watcher.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ import (
1010
"github.com/docker/docker/api/types/container"
1111
"github.com/docker/docker/api/types/events"
1212
"github.com/docker/docker/api/types/filters"
13-
"github.com/docker/docker/client"
1413
)
1514

15+
// DockerClient is the subset of the Docker API used by the Watcher.
16+
// The full client.APIClient satisfies this interface.
17+
type DockerClient interface {
18+
Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error)
19+
ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)
20+
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
21+
}
22+
1623
type ContainerInfo struct {
1724
Project string
1825
Service string
@@ -25,12 +32,12 @@ type EventHandler interface {
2532
}
2633

2734
type Watcher struct {
28-
docker client.APIClient
35+
docker DockerClient
2936
handler EventHandler
3037
projectMu sync.Map // map[string]*sync.Mutex
3138
}
3239

33-
func New(docker client.APIClient, handler EventHandler) *Watcher {
40+
func New(docker DockerClient, handler EventHandler) *Watcher {
3441
return &Watcher{
3542
docker: docker,
3643
handler: handler,

0 commit comments

Comments
 (0)