Patrick Venture | aceb4ba | 2018-09-27 14:50:37 -0700 | [diff] [blame] | 1 | #include <blobs-ipmid/manager.hpp> |
Patrick Venture | 7210b31 | 2018-10-03 14:01:35 -0700 | [diff] [blame] | 2 | #include <blobs-ipmid/test/blob_mock.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::Return; |
| 10 | |
| 11 | TEST(ManagerStatTest, StatNoHandler) |
| 12 | { |
| 13 | // There is no handler for this path. |
| 14 | |
| 15 | BlobManager mgr; |
| 16 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 17 | auto m1ptr = m1.get(); |
| 18 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 19 | |
| 20 | struct BlobMeta meta; |
| 21 | std::string path = "/asdf/asdf"; |
| 22 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(false)); |
| 23 | |
| 24 | EXPECT_FALSE(mgr.stat(path, &meta)); |
| 25 | } |
| 26 | |
| 27 | TEST(ManagerStatTest, StatHandlerFoundButFails) |
| 28 | { |
| 29 | // There is a handler for this path but Stat fails. |
| 30 | |
| 31 | BlobManager mgr; |
| 32 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 33 | auto m1ptr = m1.get(); |
| 34 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 35 | |
| 36 | struct BlobMeta meta; |
| 37 | std::string path = "/asdf/asdf"; |
| 38 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 39 | EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(false)); |
| 40 | |
| 41 | EXPECT_FALSE(mgr.stat(path, &meta)); |
| 42 | } |
| 43 | |
| 44 | TEST(ManagerStatTest, StatHandlerFoundAndSucceeds) |
| 45 | { |
| 46 | // There is a handler and Stat succeeds. |
| 47 | |
| 48 | BlobManager mgr; |
| 49 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 50 | auto m1ptr = m1.get(); |
| 51 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 52 | |
| 53 | struct BlobMeta meta; |
| 54 | std::string path = "/asdf/asdf"; |
| 55 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 56 | EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(true)); |
| 57 | |
| 58 | EXPECT_TRUE(mgr.stat(path, &meta)); |
| 59 | } |
| 60 | } // namespace blobs |