From fcce2befd3d367888ba931804c8c00aff30a16e1 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 10 Feb 2025 11:38:41 +0000 Subject: [PATCH 1/2] chore(agent/agentcontainers): skip TestDockerCLIContainerLister by default --- .../agentcontainers/containers_internal_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/agent/agentcontainers/containers_internal_test.go b/agent/agentcontainers/containers_internal_test.go index b9f34261ddcad..e15deae54c2bd 100644 --- a/agent/agentcontainers/containers_internal_test.go +++ b/agent/agentcontainers/containers_internal_test.go @@ -2,8 +2,7 @@ package agentcontainers import ( "fmt" - "os/exec" - "runtime" + "os" "strconv" "strings" "testing" @@ -27,15 +26,14 @@ import ( // dockerCLIContainerLister.List method. It starts a container with a known // label, lists the containers, and verifies that the expected container is // returned. The container is deleted after the test is complete. +// As this test creates containers, it is skipped by default. +// It can be run manually as follows: +// +// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerCLIContainerLister func TestDockerCLIContainerLister(t *testing.T) { t.Parallel() - if runtime.GOOS != "linux" { - t.Skip("creating containers on non-linux runners is slow and flaky") - } - - // Conditionally skip if Docker is not available. - if _, err := exec.LookPath("docker"); err != nil { - t.Skip("docker not found in PATH") + if ctud, ok := os.LookupEnv("CODER_TEST_USE_DOCKER"); !ok || ctud != "1" { + t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test") } pool, err := dockertest.NewPool("") From 6f1731ec9d5c54feb4b9d8745b8b3b05656e63ce Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 10 Feb 2025 11:53:49 +0000 Subject: [PATCH 2/2] fix(agent/agentcontainers): exit early if there are no container IDs --- agent/agentcontainers/containers_dockercli.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/agent/agentcontainers/containers_dockercli.go b/agent/agentcontainers/containers_dockercli.go index e7364125b8e0f..3842735116329 100644 --- a/agent/agentcontainers/containers_dockercli.go +++ b/agent/agentcontainers/containers_dockercli.go @@ -59,6 +59,11 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi } dockerPsStderr := strings.TrimSpace(stderrBuf.String()) + if len(ids) == 0 { + return codersdk.WorkspaceAgentListContainersResponse{ + Warnings: []string{dockerPsStderr}, + }, nil + } // now we can get the detailed information for each container // Run `docker inspect` on each container ID