Skip to content

Commit

Permalink
Use relative path for temp dirs in test
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed Apr 22, 2020
1 parent 3f3f4b2 commit 971af1a
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.dockerjava.api.command.PullImageResultCallback;
import com.github.dockerjava.api.model.AuthConfig;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -110,7 +111,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 tempContext = getLocalTempDir();
Path tempFile = Files.createTempFile(tempContext, "test", ".Dockerfile");
String dockerFileContent = "FROM " + testImageNameWithTag;
Files.write(tempFile, dockerFileContent.getBytes());
Expand All @@ -130,7 +131,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 tempContext = getLocalTempDir();
Path tempFile = Files.createTempFile(tempContext, "test", ".docker-compose.yml");
@Language("yaml") String composeFileContent =
"version: '2.0'\n" +
Expand All @@ -153,6 +154,13 @@ public void testThatAuthLocatorIsUsedForDockerComposePull() throws IOException {
}
}

@NotNull
private Path getLocalTempDir() throws IOException {
Path projectRoot = Paths.get(".");
Path tempDirectory = Files.createTempDirectory(projectRoot, this.getClass().getSimpleName() + "-test-");
return projectRoot.relativize(tempDirectory);
}

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 971af1a

Please sign in to comment.