From fbadada0697c9ac3c69049b77c68e4e231a507fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 21 Aug 2024 12:30:19 +0200 Subject: [PATCH] fix: update tests --- internal/core/docker_host.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/internal/core/docker_host.go b/internal/core/docker_host.go index beb959a712..e8db3fe182 100644 --- a/internal/core/docker_host.go +++ b/internal/core/docker_host.go @@ -116,22 +116,6 @@ func extractDockerHost(ctx context.Context) string { continue } - // check if the docker host responds to an Info request - // we are going to use the default Docker client to check if the host is reachable - // which will avoid recursive calls to this function - cli, err := client.NewClientWithOpts(client.WithHost(dockerHost)) - if err != nil { - outerErr = fmt.Errorf("%w: %w", outerErr, err) - continue - } - defer cli.Close() - - _, err = cli.Info(ctx) - if err != nil { - outerErr = fmt.Errorf("%w: %w", outerErr, err) - continue - } - return dockerHost } @@ -157,7 +141,8 @@ func extractDockerSocket(ctx context.Context) string { // and receiving an instance of the Docker API client interface. // This internal method is handy for testing purposes, passing a mock type simulating the desired behaviour. func extractDockerSocketFromClient(ctx context.Context, cli client.APIClient) string { - // check that the socket is not a tcp or unix socket + // check that the socket is not a tcp or unix socket, + // and that it is reachable. checkDockerSocketFn := func(socket string) string { // this use case will cover the case when the docker host is a tcp socket if strings.HasPrefix(socket, TCPSchema) { @@ -168,6 +153,11 @@ func extractDockerSocketFromClient(ctx context.Context, cli client.APIClient) st return strings.Replace(socket, DockerSocketSchema, "", 1) } + _, err := cli.Info(ctx) + if err != nil { + return DockerSocketPath + } + return socket }