Hello,
How to replicate:
- create directory with spaces in path
mkdir ~/dir\ with\ spaces
- move some project using testcontainers-java to that directory
- put a file to copy into container in
resources directory (touch src/test/resources/any_file in this example)
- use container loading files from class path, ie:
new GenericContainer(
new ImageFromDockerfile()
.withDockerfileFromBuilder(builder -> {
builder
.from("alpine:3.2")
.copy("any_file", "any_file")
.build();
})
)
.withFileFromClasspath("any_file", "any_file")
)
This will throw exception:
1 error
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image name from org.testcontainers.images.builder.ImageFromDockerfile@61ae0d43
Caused by: java.lang.RuntimeException: Can't get size from ~/dir%20with%20spaces/your-project/target/test-classes/any_file
Caused by: java.nio.file.NoSuchFileException: ~/dir%20with%20spaces/your-project/target/test-classes/any_file
Issue is related to urlencoded spaces in path (%20) when using
URL resource = ClasspathTrait.class.getClassLoader().getResource(resourcePath);
String resourceFilePath = new File(resource.getFile()).getAbsolutePath();
in default implementation of withFileFromClasspath. Calling .toURI() instead of .getFile() on resource should fix this issue while not breaking anything - I'm using this workaround and seems to be fine. No PR though, sorry, simply no time to do it.
Hello,
How to replicate:
resourcesdirectory (touch src/test/resources/any_filein this example)This will throw exception:
Issue is related to urlencoded spaces in path (%20) when using
in default implementation of
withFileFromClasspath. Calling.toURI()instead of.getFile()on resource should fix this issue while not breaking anything - I'm using this workaround and seems to be fine. No PR though, sorry, simply no time to do it.