Skip to content

Commit

Permalink
Reduce duplication in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Newton committed Nov 5, 2023
1 parent 87768d4 commit 4fef7e9
Showing 1 changed file with 13 additions and 52 deletions.
65 changes: 13 additions & 52 deletions cpp/src/arrow/filesystem/azurefs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class AzureFileSystemTest : public ::testing::Test {
blob_client.UploadFrom(reinterpret_cast<const uint8_t*>(all_lines.data()),
total_size);
}

void RunGetFileInfoObjectWithNestedStructureTest();
void RunGetFileInfoObjectTest();
};

class AzuriteFileSystemTest : public AzureFileSystemTest {
Expand Down Expand Up @@ -318,7 +321,7 @@ TEST_F(AzuriteFileSystemTest, GetFileInfoContainer) {
ASSERT_RAISES(Invalid, fs_->GetFileInfo("abfs://" + PreexistingContainerName()));
}

TEST_F(AzuriteFileSystemTest, GetFileInfoObjectWithNestedStructure) {
void AzureFileSystemTest::RunGetFileInfoObjectWithNestedStructureTest() {
// Adds detailed tests to handle cases of different edge cases
// with directory naming conventions (e.g. with and without slashes).
constexpr auto kObjectName = "test-object-dir/some_other_dir/another_dir/foo";
Expand Down Expand Up @@ -357,53 +360,21 @@ TEST_F(AzuriteFileSystemTest, GetFileInfoObjectWithNestedStructure) {
FileType::NotFound);
}

TEST_F(AzureHierarchicalNamespaceFileSystemTest, GetFileInfoObjectWithNestedStructure) {
// Adds detailed tests to handle cases of different edge cases
// with directory naming conventions (e.g. with and without slashes).
constexpr auto kObjectName = "test-object-dir/some_other_dir/another_dir/foo";
// TODO(GH-38333): Switch to using Azure filesystem to write once its implemented.
blob_service_client_->GetBlobContainerClient(PreexistingContainerName())
.GetBlockBlobClient(kObjectName)
.UploadFrom(reinterpret_cast<const uint8_t*>(kLoremIpsum), strlen(kLoremIpsum));

// 0 is immediately after "/" lexicographically, ensure that this doesn't
// cause unexpected issues.
// TODO(GH-38333): Switch to using Azure filesystem to write once its implemented.
blob_service_client_->GetBlobContainerClient(PreexistingContainerName())
.GetBlockBlobClient("test-object-dir/some_other_dir0")
.UploadFrom(reinterpret_cast<const uint8_t*>(kLoremIpsum), strlen(kLoremIpsum));

blob_service_client_->GetBlobContainerClient(PreexistingContainerName())
.GetBlockBlobClient(std::string(kObjectName) + "0")
.UploadFrom(reinterpret_cast<const uint8_t*>(kLoremIpsum), strlen(kLoremIpsum));
TEST_F(AzuriteFileSystemTest, GetFileInfoObjectWithNestedStructure) {
RunGetFileInfoObjectWithNestedStructureTest();
}

TEST_F(AzureHierarchicalNamespaceFileSystemTest, GetFileInfoObjectWithNestedStructure) {
RunGetFileInfoObjectWithNestedStructureTest();
datalake_service_client_->GetFileSystemClient(PreexistingContainerName())
.GetDirectoryClient("test-empty-object-dir")
.Create();

AssertFileInfo(fs_.get(), PreexistingContainerPath() + kObjectName, FileType::File);
AssertFileInfo(fs_.get(), PreexistingContainerPath() + kObjectName + "/",
FileType::NotFound);
AssertFileInfo(fs_.get(), PreexistingContainerPath() + "test-object-dir",
FileType::Directory);
AssertFileInfo(fs_.get(), PreexistingContainerPath() + "test-object-dir/",
FileType::Directory);
AssertFileInfo(fs_.get(), PreexistingContainerPath() + "test-object-dir/some_other_dir",
FileType::Directory);
AssertFileInfo(fs_.get(),
PreexistingContainerPath() + "test-object-dir/some_other_dir/",
FileType::Directory);

AssertFileInfo(fs_.get(), PreexistingContainerPath() + "test-object-di",
FileType::NotFound);
AssertFileInfo(fs_.get(), PreexistingContainerPath() + "test-object-dir/some_other_di",
FileType::NotFound);

AssertFileInfo(fs_.get(), PreexistingContainerPath() + "test-empty-object-dir",
FileType::Directory);
}

TEST_F(AzuriteFileSystemTest, GetFileInfoObject) {
void AzureFileSystemTest::RunGetFileInfoObjectTest() {
auto object_properties =
blob_service_client_->GetBlobContainerClient(PreexistingContainerName())
.GetBlobClient(PreexistingObjectName())
Expand All @@ -419,20 +390,10 @@ TEST_F(AzuriteFileSystemTest, GetFileInfoObject) {
ASSERT_RAISES(Invalid, fs_->GetFileInfo("abfs://" + PreexistingObjectName()));
}

TEST_F(AzureHierarchicalNamespaceFileSystemTest, GetFileInfoObject) {
auto object_properties =
blob_service_client_->GetBlobContainerClient(PreexistingContainerName())
.GetBlobClient(PreexistingObjectName())
.GetProperties()
.Value;

arrow::fs::AssertFileInfo(
fs_.get(), PreexistingObjectPath(), FileType::File,
std::chrono::system_clock::time_point(object_properties.LastModified),
static_cast<int64_t>(object_properties.BlobSize));
TEST_F(AzuriteFileSystemTest, GetFileInfoObject) { RunGetFileInfoObjectTest(); }

// URI
ASSERT_RAISES(Invalid, fs_->GetFileInfo("abfs://" + PreexistingObjectName()));
TEST_F(AzureHierarchicalNamespaceFileSystemTest, GetFileInfoObject) {
RunGetFileInfoObjectTest();
}

TEST_F(AzuriteFileSystemTest, OpenInputStreamString) {
Expand Down

0 comments on commit 4fef7e9

Please sign in to comment.