Skip to content

Commit

Permalink
Use relative path for temp dirs in test (testcontainers#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth authored and quincy committed May 28, 2020
1 parent 5a7ef15 commit e615c72
Showing 1 changed file with 14 additions and 4 deletions.
Expand Up @@ -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());

Expand All @@ -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" +
Expand All @@ -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();
Expand Down

0 comments on commit e615c72

Please sign in to comment.