Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative path for temp dirs in test #2604

Merged
merged 2 commits into from Apr 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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-");
bsideup marked this conversation as resolved.
Show resolved Hide resolved
Path relativeTempDirectory = projectRoot.relativize(tempDirectory);
Path tempFile = Files.createTempFile(relativeTempDirectory, "test", s);

tempDirectory.toFile().deleteOnExit();
rnorth marked this conversation as resolved.
Show resolved Hide resolved
rnorth marked this conversation as resolved.
Show resolved Hide resolved
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