Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String getRemoteDockerUnixSocketPath() {

@Override
protected boolean isApplicable() {
return (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) && this.socketPath != null;
return (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) && getSocketPath() != null;
}

private Optional<Path> tryFolder(Path path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.testcontainers.dockerclient;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;

@SuppressWarnings("deprecation")
class DockerDesktopClientProviderStrategyTest {

private final String originalUserHome = System.getProperty("user.home");

@AfterEach
void restoreUserHome() {
System.setProperty("user.home", originalUserHome);
}

@Test
@EnabledOnOs({ OS.LINUX, OS.MAC })
void notApplicableWhenDockerDesktopSocketIsMissing(@TempDir Path userHome) {
// user.home without a Docker Desktop socket under .docker/desktop or .docker/run
System.setProperty("user.home", userHome.toString());

DockerDesktopClientProviderStrategy strategy = new DockerDesktopClientProviderStrategy();

assertThat(strategy.isApplicable()).isFalse();
}

@Test
@EnabledOnOs({ OS.LINUX, OS.MAC })
void applicableWhenDockerDesktopSocketExists(@TempDir Path userHome) throws IOException {
Path socketPath = userHome.resolve(".docker").resolve("desktop").resolve("docker.sock");
Files.createDirectories(socketPath.getParent());
Files.createFile(socketPath);
System.setProperty("user.home", userHome.toString());

DockerDesktopClientProviderStrategy strategy = new DockerDesktopClientProviderStrategy();

assertThat(strategy.isApplicable()).isTrue();
}
}