Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Aug 21, 2024
1 parent 19fb55b commit fbadada
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions internal/core/docker_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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) {
Expand All @@ -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
}

Expand Down

0 comments on commit fbadada

Please sign in to comment.