@@ -629,6 +629,42 @@ TEST_F(GcsIntegrationTest, GetFileInfoBucket) {
629
629
ASSERT_RAISES (Invalid, fs->GetFileInfo (" gs://" + PreexistingBucketName ()));
630
630
}
631
631
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
+
632
668
TEST_F (GcsIntegrationTest, GetFileInfoObjectWithNestedStructure) {
633
669
// Adds detailed tests to handle cases of different edge cases
634
670
// with directory naming conventions (e.g. with and without slashes).
0 commit comments