MCPcopy Create free account
hub / github.com/apache/arrow / TestMoveFile

Method TestMoveFile

cpp/src/arrow/filesystem/test_util.cc:395–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395void GenericFileSystemTest::TestMoveFile(FileSystem* fs) {
396 if (!allow_move_file()) {
397 GTEST_SKIP() << "Filesystem doesn't allow moving files";
398 }
399
400 ASSERT_OK(fs->CreateDir("AB/CD"));
401 ASSERT_OK(fs->CreateDir("EF"));
402 CreateFile(fs, "abc", "data");
403 std::vector<std::string> all_dirs{"AB", "AB/CD", "EF"};
404 AssertAllDirs(fs, all_dirs);
405 AssertAllFiles(fs, {"abc"});
406
407 // Move inside root dir
408 ASSERT_OK(fs->Move("abc", "def"));
409 AssertAllDirs(fs, all_dirs);
410 AssertAllFiles(fs, {"def"});
411 AssertFileInfo(fs, "def", FileType::File, 4);
412 AssertFileContents(fs, "def", "data");
413
414 // Move out of root dir
415 ASSERT_OK(fs->Move("def", "AB/CD/ghi"));
416 AssertAllDirs(fs, all_dirs);
417 AssertAllFiles(fs, {"AB/CD/ghi"});
418 AssertFileInfo(fs, "AB/CD/ghi", FileType::File, 4);
419 AssertFileContents(fs, "AB/CD/ghi", "data");
420
421 ASSERT_OK(fs->Move("AB/CD/ghi", "EF/jkl"));
422 AssertAllDirs(fs, all_dirs);
423 AssertAllFiles(fs, {"EF/jkl"});
424 AssertFileInfo(fs, "EF/jkl", FileType::File, 4);
425 AssertFileContents(fs, "EF/jkl", "data");
426
427 // Move back into root dir
428 ASSERT_OK(fs->Move("EF/jkl", "mno"));
429 AssertAllDirs(fs, all_dirs);
430 AssertAllFiles(fs, {"mno"});
431 AssertFileInfo(fs, "mno", FileType::File, 4);
432 AssertFileContents(fs, "mno", "data");
433
434 // Destination is a file => clobber
435 CreateFile(fs, "AB/pqr", "other data");
436 AssertAllFiles(fs, {"AB/pqr", "mno"});
437 ASSERT_OK(fs->Move("mno", "AB/pqr"));
438 AssertAllFiles(fs, {"AB/pqr"});
439 AssertFileInfo(fs, "AB/pqr", FileType::File, 4);
440 AssertFileContents(fs, "AB/pqr", "data");
441
442 // Identical source and destination: allowed to succeed or raise IOError,
443 // but should not lose data.
444 auto err = fs->Move("AB/pqr", "AB/pqr");
445 if (!err.ok()) {
446 ASSERT_RAISES(IOError, err);
447 }
448 AssertAllFiles(fs, {"AB/pqr"});
449 AssertFileInfo(fs, "AB/pqr", FileType::File, 4);
450 AssertFileContents(fs, "AB/pqr", "data");
451
452 // Source doesn't exist

Callers

nothing calls this directly

Calls 12

allow_move_fileFunction · 0.85
CreateFileFunction · 0.85
AssertAllDirsFunction · 0.85
AssertAllFilesFunction · 0.85
AssertFileInfoFunction · 0.85
AssertFileContentsFunction · 0.70
CreateDirMethod · 0.45
MoveMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected