Skip to content

Commit a12429e

Browse files
authored
feat(agent/agentcontainers): refactor Lister to ContainerCLI and implement new methods (#18243)
1 parent 533c6dc commit a12429e

File tree

11 files changed

+367
-95
lines changed

11 files changed

+367
-95
lines changed

agent/agentcontainers/acmock/acmock.go

Lines changed: 65 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/agentcontainers/acmock/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Package acmock contains a mock implementation of agentcontainers.Lister for use in tests.
22
package acmock
33

4-
//go:generate mockgen -destination ./acmock.go -package acmock .. Lister,DevcontainerCLI
4+
//go:generate mockgen -destination ./acmock.go -package acmock .. ContainerCLI,DevcontainerCLI

agent/agentcontainers/api.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type API struct {
4343
logger slog.Logger
4444
watcher watcher.Watcher
4545
execer agentexec.Execer
46-
cl Lister
46+
ccli ContainerCLI
4747
dccli DevcontainerCLI
4848
clock quartz.Clock
4949
scriptLogger func(logSourceID uuid.UUID) ScriptLogger
@@ -80,11 +80,11 @@ func WithExecer(execer agentexec.Execer) Option {
8080
}
8181
}
8282

83-
// WithLister sets the agentcontainers.Lister implementation to use.
84-
// The default implementation uses the Docker CLI to list containers.
85-
func WithLister(cl Lister) Option {
83+
// WithContainerCLI sets the agentcontainers.ContainerCLI implementation
84+
// to use. The default implementation uses the Docker CLI.
85+
func WithContainerCLI(ccli ContainerCLI) Option {
8686
return func(api *API) {
87-
api.cl = cl
87+
api.ccli = ccli
8888
}
8989
}
9090

@@ -186,8 +186,8 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
186186
for _, opt := range options {
187187
opt(api)
188188
}
189-
if api.cl == nil {
190-
api.cl = NewDocker(api.execer)
189+
if api.ccli == nil {
190+
api.ccli = NewDockerCLI(api.execer)
191191
}
192192
if api.dccli == nil {
193193
api.dccli = NewDevcontainerCLI(logger.Named("devcontainer-cli"), api.execer)
@@ -363,7 +363,7 @@ func (api *API) updateContainers(ctx context.Context) error {
363363
listCtx, listCancel := context.WithTimeout(ctx, listContainersTimeout)
364364
defer listCancel()
365365

366-
updated, err := api.cl.List(listCtx)
366+
updated, err := api.ccli.List(listCtx)
367367
if err != nil {
368368
// If the context was canceled, we hold off on clearing the
369369
// containers cache. This is to avoid clearing the cache if

0 commit comments

Comments
 (0)