Skip to content

Commit cfb755a

Browse files
committed
ADD: getFileInfo test code added
1 parent be55f8a commit cfb755a

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

cpp/src/arrow/filesystem/gcsfs.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ class GcsFileSystem::Impl {
353353
// matches the prefix we assume it is a directory.
354354
std::string canonical = internal::EnsureTrailingSlash(path.object);
355355
auto list_result = client_.ListObjects(path.bucket, gcs::Prefix(canonical));
356-
356+
357357
// Check that the result is valid before determining whether the list is empty.
358-
if (list_result.begin() != list_result.end() && *list_result.begin()) {
358+
auto it = list_result.begin();
359+
if (it != list_result.end() && *it) {
359360
// If there is at least one result it indicates this is a directory (at
360361
// least one object exists that starts with "path/")
361362
return FileInfo(path.full_path, FileType::Directory);

cpp/src/arrow/filesystem/gcsfs_test.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,42 @@ TEST_F(GcsIntegrationTest, GetFileInfoBucket) {
629629
ASSERT_RAISES(Invalid, fs->GetFileInfo("gs://" + PreexistingBucketName()));
630630
}
631631

632+
TEST_F(GcsIntegrationTest, GetFileInfo) {
633+
ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(TestGcsOptions()));
634+
constexpr auto kTextFileName = "dir/foo/bar.txt";
635+
ASSERT_OK_AND_ASSIGN(
636+
auto output,
637+
fs->OpenOutputStream(PreexistingBucketPath() + kTextFileName, /*metadata=*/{}));
638+
const auto data = std::string(kLoremIpsum);
639+
ASSERT_OK(output->Write(data.data(), data.size()));
640+
ASSERT_OK(output->Close());
641+
642+
// check this is the File.
643+
AssertFileInfo(fs.get(), PreexistingBucketPath() + kTextFileName, FileType::File);
644+
645+
// check parent directories are recognized as directories.
646+
AssertFileInfo(fs.get(), PreexistingBucketPath() + "dir/", FileType::Directory);
647+
AssertFileInfo(fs.get(), PreexistingBucketPath() + "dir/foo/", FileType::Directory);
648+
}
649+
650+
TEST_F(GcsIntegrationTest, GetFileInfo_WithoutPermission) {
651+
TimePoint expiration = std::chrono::system_clock::now() + std::chrono::minutes(5);
652+
auto options =
653+
GcsOptions::FromAccessToken(/*access_token=*/"invalid-access-token", expiration);
654+
options.endpoint_override = "127.0.0.1:" + Testbench()->port();
655+
656+
ASSERT_OK_AND_ASSIGN(auto fs, GcsFileSystem::Make(options));
657+
658+
constexpr auto kTextFileName = "dir/foo/bar.txt";
659+
660+
// check this is the File without permission.
661+
AssertFileInfo(fs.get(), PreexistingBucketPath() + kTextFileName, FileType::NotFound);
662+
663+
// check this is the directory without permission.
664+
AssertFileInfo(fs.get(), PreexistingBucketPath() + "dir/", FileType::NotFound);
665+
AssertFileInfo(fs.get(), PreexistingBucketPath() + "dir/foo/", FileType::NotFound);
666+
}
667+
632668
TEST_F(GcsIntegrationTest, GetFileInfoObjectWithNestedStructure) {
633669
// Adds detailed tests to handle cases of different edge cases
634670
// with directory naming conventions (e.g. with and without slashes).

0 commit comments

Comments
 (0)