Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 1 | #include "blob_mock.hpp" |
| 2 | #include "manager.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 3 | |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | namespace blobs |
| 7 | { |
| 8 | |
| 9 | using ::testing::_; |
| 10 | using ::testing::Return; |
| 11 | |
| 12 | TEST(ManagerSessionStatTest, StatNoSessionReturnsFalse) |
| 13 | { |
| 14 | // Calling Stat on a session that doesn't exist should return false. |
| 15 | |
| 16 | BlobManager mgr; |
| 17 | struct BlobMeta meta; |
| 18 | uint16_t sess = 1; |
| 19 | |
| 20 | EXPECT_FALSE(mgr.stat(sess, &meta)); |
| 21 | } |
| 22 | |
| 23 | TEST(ManagerSessionStatTest, StatSessionFoundButHandlerReturnsFalse) |
| 24 | { |
| 25 | // The handler was found but it returned failure. |
| 26 | |
| 27 | BlobManager mgr; |
| 28 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 29 | auto m1ptr = m1.get(); |
| 30 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 31 | |
| 32 | uint16_t flags = OpenFlags::read, sess; |
| 33 | std::string path = "/asdf/asdf"; |
| 34 | |
| 35 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 36 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 37 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 38 | |
| 39 | struct BlobMeta meta; |
| 40 | EXPECT_CALL(*m1ptr, stat(sess, &meta)).WillOnce(Return(false)); |
| 41 | |
| 42 | EXPECT_FALSE(mgr.stat(sess, &meta)); |
| 43 | } |
| 44 | |
| 45 | TEST(ManagerSessionStatTest, StatSessionFoundAndHandlerReturnsSuccess) |
| 46 | { |
| 47 | // The handler was found and returned success. |
| 48 | |
| 49 | BlobManager mgr; |
| 50 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 51 | auto m1ptr = m1.get(); |
| 52 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 53 | |
| 54 | uint16_t flags = OpenFlags::read, sess; |
| 55 | std::string path = "/asdf/asdf"; |
| 56 | |
| 57 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 58 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 59 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 60 | |
| 61 | struct BlobMeta meta; |
| 62 | EXPECT_CALL(*m1ptr, stat(sess, &meta)).WillOnce(Return(true)); |
| 63 | |
| 64 | EXPECT_TRUE(mgr.stat(sess, &meta)); |
| 65 | } |
| 66 | } // namespace blobs |