diff --git a/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java b/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java index 56945643a88..5f4417f218b 100644 --- a/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java +++ b/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java @@ -110,8 +110,7 @@ public void testThatAuthLocatorIsUsedForContainerCreation() { @Test public void testThatAuthLocatorIsUsedForDockerfileBuild() throws IOException { // Prepare a simple temporary Dockerfile which requires our custom private image - Path tempContext = Files.createTempDirectory(Paths.get("."), this.getClass().getSimpleName() + "-test-"); - Path tempFile = Files.createTempFile(tempContext, "test", ".Dockerfile"); + Path tempFile = getLocalTempFile(".Dockerfile"); String dockerFileContent = "FROM " + testImageNameWithTag; Files.write(tempFile, dockerFileContent.getBytes()); @@ -130,8 +129,7 @@ public void testThatAuthLocatorIsUsedForDockerfileBuild() throws IOException { @Test public void testThatAuthLocatorIsUsedForDockerComposePull() throws IOException { // Prepare a simple temporary Docker Compose manifest which requires our custom private image - Path tempContext = Files.createTempDirectory(Paths.get("."), this.getClass().getSimpleName() + "-test-"); - Path tempFile = Files.createTempFile(tempContext, "test", ".docker-compose.yml"); + Path tempFile = getLocalTempFile(".docker-compose.yml"); @Language("yaml") String composeFileContent = "version: '2.0'\n" + "services:\n" + @@ -153,6 +151,18 @@ public void testThatAuthLocatorIsUsedForDockerComposePull() throws IOException { } } + private Path getLocalTempFile(String s) throws IOException { + Path projectRoot = Paths.get("."); + Path tempDirectory = Files.createTempDirectory(projectRoot, this.getClass().getSimpleName() + "-test-"); + Path relativeTempDirectory = projectRoot.relativize(tempDirectory); + Path tempFile = Files.createTempFile(relativeTempDirectory, "test", s); + + tempDirectory.toFile().deleteOnExit(); + tempFile.toFile().deleteOnExit(); + + return tempFile; + } + private static void putImageInRegistry() throws InterruptedException { // It doesn't matter which image we use for this test, but use one that's likely to have been pulled already final String dummySourceImage = TestcontainersConfiguration.getInstance().getRyukImage();