From da970b36c9733ce0a320537dbc510b7e98094f4e Mon Sep 17 00:00:00 2001 From: Andrew Roskuski Date: Wed, 15 Dec 2021 03:12:28 -0500 Subject: [PATCH] Fix unit test failures on Windows --- .../core/DefaultDockerClientConfigTest.java | 10 ++++++++-- .../dockerjava/core/util/CompressArchiveUtilTest.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docker-java/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java b/docker-java/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java index 8c1071aa6..ced61a015 100644 --- a/docker-java/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java +++ b/docker-java/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java @@ -5,6 +5,7 @@ import com.github.dockerjava.api.model.AuthConfigurations; import com.google.common.io.Resources; import org.apache.commons.lang3.SerializationUtils; +import org.apache.commons.lang3.SystemUtils; import org.junit.Test; import java.io.File; @@ -97,8 +98,11 @@ public void emptyHost() { DefaultDockerClientConfig config = buildConfig(env, new Properties()); + String expectedDefaultHost = SystemUtils.IS_OS_WINDOWS ? DefaultDockerClientConfig.WINDOWS_DEFAULT_DOCKER_HOST + : DefaultDockerClientConfig.DEFAULT_DOCKER_HOST; + assertEquals( - DefaultDockerClientConfig.DEFAULT_DOCKER_HOST, + expectedDefaultHost, config.getDockerHost().toString() ); } @@ -119,7 +123,9 @@ public void defaults() throws Exception { DefaultDockerClientConfig config = buildConfig(Collections. emptyMap(), systemProperties); // then the cert path is as expected - assertEquals(config.getDockerHost(), URI.create("unix:///var/run/docker.sock")); + URI expectedDefaultURI = SystemUtils.IS_OS_WINDOWS ? URI.create(DefaultDockerClientConfig.WINDOWS_DEFAULT_DOCKER_HOST) + : URI.create(DefaultDockerClientConfig.DEFAULT_DOCKER_HOST); + assertEquals(config.getDockerHost(), expectedDefaultURI); assertEquals(config.getRegistryUsername(), "someUserName"); assertEquals(config.getRegistryUrl(), AuthConfig.DEFAULT_SERVER_ADDRESS); assertEquals(config.getApiVersion(), RemoteApiVersion.unknown()); diff --git a/docker-java/src/test/java/com/github/dockerjava/core/util/CompressArchiveUtilTest.java b/docker-java/src/test/java/com/github/dockerjava/core/util/CompressArchiveUtilTest.java index 720441e20..586314b50 100644 --- a/docker-java/src/test/java/com/github/dockerjava/core/util/CompressArchiveUtilTest.java +++ b/docker-java/src/test/java/com/github/dockerjava/core/util/CompressArchiveUtilTest.java @@ -2,6 +2,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.lang3.SystemUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -22,6 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; public class CompressArchiveUtilTest { @@ -69,6 +71,7 @@ public void tarWithExecutableFileAsInput() throws Exception { @Test public void tarWithSymbolicLinkFileAsInput() throws IOException { + assumeSymbolicLinksAreUnrestrictedByDefault(); Path archiveSourceFile = tempFolder.getRoot().toPath().resolve("symlinkFile"); Path linkTargetFile = tempFolder.newFile("link-target").toPath(); Files.createSymbolicLink(archiveSourceFile, linkTargetFile); @@ -139,6 +142,7 @@ public void tarWithfolderAsInputAndNestedExecutableFile() throws Exception { @Test public void tarWithfolderAsInputAndNestedSymbolicLinkFile() throws Exception { + assumeSymbolicLinksAreUnrestrictedByDefault(); Path archiveSourceDir = tempFolder.newFolder("archive-source").toPath(); Path linkTargetFile = tempFolder.newFile("link-target").toPath(); Path symlinkFile = archiveSourceDir.resolve("symlinkFile"); @@ -160,6 +164,7 @@ public void tarWithfolderAsInputAndNestedSymbolicLinkFile() throws Exception { @Test public void tarWithfolderAsInputAndNestedSymbolicLinkDir() throws Exception { + assumeSymbolicLinksAreUnrestrictedByDefault(); Path archiveSourceDir = tempFolder.newFolder("archive-source").toPath(); Path linkTargetDir = tempFolder.newFolder("link-target").toPath(); Path symlinkFile = archiveSourceDir.resolve("symlinkFile"); @@ -204,6 +209,7 @@ public void archiveTARFilesWithExecutableFile() throws Exception { @Test public void archiveTARFilesWithSymbolicLinkFile() throws Exception { + assumeSymbolicLinksAreUnrestrictedByDefault(); Path linkTargetFile = tempFolder.newFile("link-target").toPath(); Path symlinkFile = tempFolder.getRoot().toPath().resolve("symlinkFile"); Files.createSymbolicLink(symlinkFile, linkTargetFile); @@ -215,6 +221,7 @@ public void archiveTARFilesWithSymbolicLinkFile() throws Exception { @Test public void archiveTARFilesWithSymbolicLinkDir() throws Exception { + assumeSymbolicLinksAreUnrestrictedByDefault(); Path linkTargetDir = tempFolder.newFolder("link-target").toPath(); Path symlinkFile = tempFolder.getRoot().toPath().resolve("symlinkFile"); Files.createSymbolicLink(symlinkFile, linkTargetDir); @@ -317,4 +324,8 @@ private static int getNumberOfEntryInArchive(File tarArchive) throws IOException } return numberOfEntries; } + + private static void assumeSymbolicLinksAreUnrestrictedByDefault(){ + assumeFalse(SystemUtils.IS_OS_WINDOWS); + } }