Skip to content

Commit 857c8d9

Browse files
Update testListFilesInRootDirectory to match reality
In the built-in UNIX filesystem, the newDirectoryStream method will return absolute paths if given absolute paths as input, and relative paths if given relative paths as input. We're now seeing this too for the NIO Cloud Storage provider (this is a good thing), so I updated this test to reflect this new reality.
1 parent d5e1529 commit 857c8d9

File tree

1 file changed

+10
-3
lines changed
  • google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/it

1 file changed

+10
-3
lines changed

google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/it/ITGcsNio.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.nio.file.Files;
5555
import java.nio.file.NoSuchFileException;
5656
import java.nio.file.Path;
57+
import java.nio.file.Paths;
5758
import java.nio.file.SimpleFileVisitor;
5859
import java.nio.file.StandardCopyOption;
5960
import java.nio.file.StandardOpenOption;
@@ -615,11 +616,17 @@ public void testListFilesInRootDirectory() throws IOException {
615616
// test absolute path, relative path.
616617
for (String check : new String[]{".", "/", ""}) {
617618
Path rootPath = fs.getPath(check);
618-
List<String> objectNames = new ArrayList<>();
619+
List<Path> pathsFound = new ArrayList<>();
619620
for (Path path : Files.newDirectoryStream(rootPath)) {
620-
objectNames.add(path.toString());
621+
// The returned paths will match the absolute-ness of the root path
622+
// (this matches the behavior of the built-in UNIX file system).
623+
assertWithMessage("Absolute/relative for " + check + ": ")
624+
.that(path.isAbsolute()).isEqualTo(rootPath.isAbsolute());
625+
// To simplify the check that we found our files, we normalize here.
626+
pathsFound.add(path.toAbsolutePath());
621627
}
622-
assertWithMessage("Listing " + check + ": ").that(objectNames).containsExactly(BIG_FILE, SML_FILE);
628+
assertWithMessage("Listing " + check + ": ").that(pathsFound).containsExactly(
629+
fs.getPath(BIG_FILE).toAbsolutePath(), fs.getPath(SML_FILE).toAbsolutePath());
623630
}
624631
}
625632

0 commit comments

Comments
 (0)