| 110 | }; // namespace |
| 111 | |
| 112 | void AssertFileContents(FileSystem* fs, const std::string& path, |
| 113 | const std::string& expected_data) { |
| 114 | ASSERT_OK_AND_ASSIGN(FileInfo info, fs->GetFileInfo(path)); |
| 115 | ASSERT_EQ(info.type(), FileType::File) << "For path '" << path << "'"; |
| 116 | ASSERT_EQ(info.size(), static_cast<int64_t>(expected_data.length())) |
| 117 | << "For path '" << path << "'"; |
| 118 | |
| 119 | ASSERT_OK_AND_ASSIGN(auto stream, fs->OpenInputStream(path)); |
| 120 | ASSERT_OK_AND_ASSIGN(auto buffer, stream->Read(info.size())); |
| 121 | AssertBufferEqual(*buffer, expected_data); |
| 122 | // No data left in stream |
| 123 | ASSERT_OK_AND_ASSIGN(auto leftover, stream->Read(1)); |
| 124 | ASSERT_EQ(leftover->size(), 0); |
| 125 | |
| 126 | ASSERT_OK(stream->Close()); |
| 127 | } |
| 128 | |
| 129 | void CreateFile(FileSystem* fs, const std::string& path, const std::string& data) { |
| 130 | ASSERT_OK_AND_ASSIGN(auto stream, fs->OpenOutputStream(path)); |
no test coverage detected