From 4d5bc312680d32b629f02468125f3e9e196d131d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 23 Aug 2023 10:44:52 +0200 Subject: [PATCH 1/3] fix: do not remove the file schema in docker.host property --- internal/testcontainersdocker/docker_host.go | 7 +---- .../testcontainersdocker/docker_host_test.go | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/internal/testcontainersdocker/docker_host.go b/internal/testcontainersdocker/docker_host.go index 6d96029a9c..f6ee5b9a50 100644 --- a/internal/testcontainersdocker/docker_host.go +++ b/internal/testcontainersdocker/docker_host.go @@ -212,12 +212,7 @@ func dockerHostFromProperties(ctx context.Context) (string, error) { cfg := config.Read() socketPath := cfg.Host if socketPath != "" { - parsed, err := parseURL(socketPath) - if err != nil { - return "", err - } - - return parsed, nil + return socketPath, nil } return "", ErrDockerSocketNotSetInProperties diff --git a/internal/testcontainersdocker/docker_host_test.go b/internal/testcontainersdocker/docker_host_test.go index 45684e134b..355ac14811 100644 --- a/internal/testcontainersdocker/docker_host_test.go +++ b/internal/testcontainersdocker/docker_host_test.go @@ -107,6 +107,16 @@ func TestExtractDockerHost(t *testing.T) { assert.Equal(t, "/this/is/a/sample.sock", host) }) + t.Run("Unix Docker Host is passed as docker.host", func(t *testing.T) { + content := "docker.host=" + DockerSocketSchema + "/this/is/a/sample.sock" + + setupTestcontainersProperties(t, content) + + host := extractDockerHost(context.Background()) + + assert.Equal(t, DockerSocketSchema+"/this/is/a/sample.sock", host) + }) + t.Run("Default Docker socket", func(t *testing.T) { setupRootlessNotFound(t) tmpSocket := setupDockerSocket(t) @@ -225,8 +235,8 @@ func TestExtractDockerHost(t *testing.T) { }) t.Run("Docker host is defined in properties", func(t *testing.T) { - tmpSocket := "/this/is/a/sample.sock" - content := "docker.host=unix://" + tmpSocket + tmpSocket := "unix:///this/is/a/sample.sock" + content := "docker.host=" + tmpSocket setupTestcontainersProperties(t, content) @@ -383,6 +393,21 @@ func TestExtractDockerSocketFromClient(t *testing.T) { socket = extractDockerSocketFromClient(ctx, mockCli{OS: "Ubuntu"}) assert.Equal(t, DockerSocketPath, socket) }) + + t.Run("Unix Docker Socket is passed as docker.host property", func(t *testing.T) { + content := "docker.host=" + DockerSocketSchema + "/this/is/a/sample.sock" + setupTestcontainersProperties(t, content) + + t.Cleanup(resetSocketOverrideFn) + + ctx := context.Background() + os.Unsetenv("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE") + os.Unsetenv("DOCKER_HOST") + + socket := extractDockerSocketFromClient(ctx, mockCli{OS: "Ubuntu"}) + + assert.Equal(t, "/this/is/a/sample.sock", socket) + }) } func TestInAContainer(t *testing.T) { From b7a7acbe8addd89fe5c40ab26fcd1b909e4c0b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 23 Aug 2023 11:56:28 +0200 Subject: [PATCH 2/3] fix: proper setup for tests --- internal/testcontainersdocker/docker_host_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/testcontainersdocker/docker_host_test.go b/internal/testcontainersdocker/docker_host_test.go index 355ac14811..6858f6edb0 100644 --- a/internal/testcontainersdocker/docker_host_test.go +++ b/internal/testcontainersdocker/docker_host_test.go @@ -108,6 +108,8 @@ func TestExtractDockerHost(t *testing.T) { }) t.Run("Unix Docker Host is passed as docker.host", func(t *testing.T) { + setupDockerSocketNotFound(t) + setupRootlessNotFound(t) content := "docker.host=" + DockerSocketSchema + "/this/is/a/sample.sock" setupTestcontainersProperties(t, content) @@ -397,6 +399,8 @@ func TestExtractDockerSocketFromClient(t *testing.T) { t.Run("Unix Docker Socket is passed as docker.host property", func(t *testing.T) { content := "docker.host=" + DockerSocketSchema + "/this/is/a/sample.sock" setupTestcontainersProperties(t, content) + setupDockerSocketNotFound(t) + setupRootlessNotFound(t) t.Cleanup(resetSocketOverrideFn) From df03fa44a54485ababbd787fe5445a92955d69c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 23 Aug 2023 17:49:35 +0200 Subject: [PATCH 3/3] fix: refine test preparation --- internal/testcontainersdocker/docker_host_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/testcontainersdocker/docker_host_test.go b/internal/testcontainersdocker/docker_host_test.go index 6858f6edb0..90ded428e6 100644 --- a/internal/testcontainersdocker/docker_host_test.go +++ b/internal/testcontainersdocker/docker_host_test.go @@ -400,7 +400,6 @@ func TestExtractDockerSocketFromClient(t *testing.T) { content := "docker.host=" + DockerSocketSchema + "/this/is/a/sample.sock" setupTestcontainersProperties(t, content) setupDockerSocketNotFound(t) - setupRootlessNotFound(t) t.Cleanup(resetSocketOverrideFn)