Skip to content

Commit 7ce35f4

Browse files
mwiedeeddumelendez
andauthored
Load test resources from classpath (#1823)
Co-authored-by: Eddú Meléndez <eddu.melendez@gmail.com>
1 parent f4cffbd commit 7ce35f4

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

docker-java/src/test/java/com/github/dockerjava/cmd/CopyArchiveFromContainerCmdIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void copyFromContainerBinaryFile() throws Exception {
6666
assertThat(container.getId(), not(isEmptyOrNullString()));
6767

6868
Path temp = Files.createTempFile("", ".tar.gz");
69-
Path binaryFile = Paths.get("src/test/resources/testCopyFromArchive/binary.dat");
69+
Path binaryFile = Paths.get(ClassLoader.getSystemResource("testCopyFromArchive/binary.dat").toURI());
7070
CompressArchiveUtil.tar(binaryFile, temp, true, false);
7171

7272
try (InputStream uploadStream = Files.newInputStream(temp)) {

docker-java/src/test/java/com/github/dockerjava/cmd/CopyArchiveToContainerCmdIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class CopyArchiveToContainerCmdIT extends CmdIT {
3333
public void copyFileToContainer() throws Exception {
3434
CreateContainerResponse container = prepareContainerForCopy("1");
3535
Path temp = Files.createTempFile("", ".tar.gz");
36-
CompressArchiveUtil.tar(Paths.get("src/test/resources/testReadFile"), temp, true, false);
36+
CompressArchiveUtil.tar(Paths.get(ClassLoader.getSystemResource("testReadFile").toURI()), temp, true, false);
3737
try (InputStream uploadStream = Files.newInputStream(temp)) {
3838
dockerRule.getClient()
3939
.copyArchiveToContainerCmd(container.getId())
@@ -47,16 +47,16 @@ public void copyFileToContainer() throws Exception {
4747
public void copyStreamToContainer() throws Exception {
4848
CreateContainerResponse container = prepareContainerForCopy("2");
4949
dockerRule.getClient().copyArchiveToContainerCmd(container.getId())
50-
.withHostResource("src/test/resources/testReadFile")
50+
.withHostResource(Paths.get(ClassLoader.getSystemResource("testReadFile").toURI()).toString())
5151
.exec();
5252
assertFileCopied(container);
5353
}
5454

5555
@Test
5656
public void copyStreamToContainerTwice() throws Exception {
5757
CreateContainerResponse container = prepareContainerForCopy("rerun");
58-
CopyArchiveToContainerCmd copyArchiveToContainerCmd=dockerRule.getClient().copyArchiveToContainerCmd(container.getId())
59-
.withHostResource("src/test/resources/testReadFile");
58+
CopyArchiveToContainerCmd copyArchiveToContainerCmd = dockerRule.getClient().copyArchiveToContainerCmd(container.getId())
59+
.withHostResource(Paths.get(ClassLoader.getSystemResource("testReadFile").toURI()).toString());
6060
copyArchiveToContainerCmd.exec();
6161
assertFileCopied(container);
6262
//run again to make sure no DockerClientException
@@ -82,9 +82,9 @@ private void assertFileCopied(CreateContainerResponse container) throws IOExcept
8282
}
8383

8484
@Test(expected = NotFoundException.class)
85-
public void copyToNonExistingContainer() {
86-
87-
dockerRule.getClient().copyArchiveToContainerCmd("non-existing").withHostResource("src/test/resources/testReadFile").exec();
85+
public void copyToNonExistingContainer() throws Exception {
86+
dockerRule.getClient().copyArchiveToContainerCmd("non-existing")
87+
.withHostResource(Paths.get(ClassLoader.getSystemResource("testReadFile").toURI()).toString()).exec();
8888
}
8989

9090
@Test
@@ -113,7 +113,7 @@ public void copyDirWithLastAddedTarEntryEmptyDir() throws Exception{
113113
// cleanup dir
114114
FileUtils.deleteDirectory(localDir.toFile());
115115
}
116-
116+
117117
@Test
118118
public void copyFileWithExecutePermission() throws Exception {
119119
// create script file, add permission to execute
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.utils;
22

3+
import java.net.URISyntaxException;
34
import java.nio.file.Path;
45
import java.nio.file.Paths;
56

@@ -8,7 +9,7 @@ public class TestResources {
89
private TestResources() {
910
}
1011

11-
public static Path getApiImagesLoadTestTarball() {
12-
return Paths.get("src/test/resources/api/images/load/image.tar");
12+
public static Path getApiImagesLoadTestTarball() throws URISyntaxException {
13+
return Paths.get(ClassLoader.getSystemResource("api/images/load/image.tar").toURI());
1314
}
1415
}

0 commit comments

Comments
 (0)