@@ -110,8 +110,7 @@ public void testThatAuthLocatorIsUsedForContainerCreation() {
110110 @ Test
111111 public void testThatAuthLocatorIsUsedForDockerfileBuild () throws IOException {
112112 // Prepare a simple temporary Dockerfile which requires our custom private image
113- Path tempContext = Files .createTempDirectory (Paths .get ("." ), this .getClass ().getSimpleName () + "-test-" );
114- Path tempFile = Files .createTempFile (tempContext , "test" , ".Dockerfile" );
113+ Path tempFile = getLocalTempFile (".Dockerfile" );
115114 String dockerFileContent = "FROM " + testImageNameWithTag ;
116115 Files .write (tempFile , dockerFileContent .getBytes ());
117116
@@ -130,8 +129,7 @@ public void testThatAuthLocatorIsUsedForDockerfileBuild() throws IOException {
130129 @ Test
131130 public void testThatAuthLocatorIsUsedForDockerComposePull () throws IOException {
132131 // Prepare a simple temporary Docker Compose manifest which requires our custom private image
133- Path tempContext = Files .createTempDirectory (Paths .get ("." ), this .getClass ().getSimpleName () + "-test-" );
134- Path tempFile = Files .createTempFile (tempContext , "test" , ".docker-compose.yml" );
132+ Path tempFile = getLocalTempFile (".docker-compose.yml" );
135133 @ Language ("yaml" ) String composeFileContent =
136134 "version: '2.0'\n " +
137135 "services:\n " +
@@ -153,6 +151,18 @@ public void testThatAuthLocatorIsUsedForDockerComposePull() throws IOException {
153151 }
154152 }
155153
154+ private Path getLocalTempFile (String s ) throws IOException {
155+ Path projectRoot = Paths .get ("." );
156+ Path tempDirectory = Files .createTempDirectory (projectRoot , this .getClass ().getSimpleName () + "-test-" );
157+ Path relativeTempDirectory = projectRoot .relativize (tempDirectory );
158+ Path tempFile = Files .createTempFile (relativeTempDirectory , "test" , s );
159+
160+ tempDirectory .toFile ().deleteOnExit ();
161+ tempFile .toFile ().deleteOnExit ();
162+
163+ return tempFile ;
164+ }
165+
156166 private static void putImageInRegistry () throws InterruptedException {
157167 // It doesn't matter which image we use for this test, but use one that's likely to have been pulled already
158168 final String dummySourceImage = TestcontainersConfiguration .getInstance ().getRyukImage ();
0 commit comments