Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not remove the file schema in docker.host property #1517

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions internal/testcontainersdocker/docker_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions internal/testcontainersdocker/docker_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ 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) {
setupDockerSocketNotFound(t)
setupRootlessNotFound(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)
Expand Down Expand Up @@ -225,8 +237,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)

Expand Down Expand Up @@ -383,6 +395,22 @@ 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)
setupDockerSocketNotFound(t)

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) {
Expand Down