Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vGsteiger committed Oct 19, 2023
1 parent 382fa34 commit 9db793f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ int64_t LocalFilesystemWrapper::get_modified_time(const std::string& path) {
ASSERT(is_valid_path(path), fmt::format("Invalid path: {}", path));
ASSERT(exists(path), fmt::format("Path does not exist: {}", path));

const std::filesystem::file_time_type time = std::filesystem::last_write_time(path);
return std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch()).count();
// For the most system reliable way to get the file timestamp, we use stat
struct stat file_stat;
if (stat(path.c_str(), &file_stat) != 0) {
FAIL(fmt::format("File timestamp not readable: {}", path));
}

time_t file_timestamp = file_stat.st_mtime;
int64_t int64_file_timestamp = static_cast<int64_t>(file_timestamp);
return int64_file_timestamp;
}

bool LocalFilesystemWrapper::is_valid_path(const std::string& path) { return std::filesystem::exists(path); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ TEST_F(LocalFilesystemWrapperTest, TestListRecursive) {
std::vector<std::string> files = filesystem_wrapper.list(test_base_dir, /*recursive=*/true);
ASSERT_EQ(files.size(), 2);
const std::string file_name = test_base_dir + path_seperator + "test_file.txt";
ASSERT_EQ((files)[1], file_name);
const std::string file_name_2 = test_base_dir + path_seperator + "test_dir_2/test_file_2.txt";
ASSERT_EQ((files)[0], file_name_2);
ASSERT_TRUE(std::find(files.begin(), files.end(), file_name) != files.end());
ASSERT_TRUE(std::find(files.begin(), files.end(), file_name_2) != files.end());
}

TEST_F(LocalFilesystemWrapperTest, TestIsDirectory) {
Expand Down

0 comments on commit 9db793f

Please sign in to comment.