Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #include "blob_mock.hpp" |
Patrick Venture | aceb4ba | 2018-09-27 14:50:37 -0700 | [diff] [blame^] | 2 | |
| 3 | #include <blobs-ipmid/manager.hpp> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace blobs |
| 8 | { |
| 9 | |
| 10 | using ::testing::_; |
| 11 | using ::testing::Return; |
| 12 | |
| 13 | TEST(ManagerCloseTest, CloseNoSessionReturnsFalse) |
| 14 | { |
| 15 | // Calling Close on a session that doesn't exist should return false. |
| 16 | |
| 17 | BlobManager mgr; |
| 18 | uint16_t sess = 1; |
| 19 | |
| 20 | EXPECT_FALSE(mgr.close(sess)); |
| 21 | } |
| 22 | |
| 23 | TEST(ManagerCloseTest, CloseSessionFoundButHandlerReturnsFalse) |
| 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 | EXPECT_CALL(*m1ptr, close(sess)).WillOnce(Return(false)); |
| 40 | |
| 41 | EXPECT_FALSE(mgr.close(sess)); |
| 42 | |
| 43 | // TODO(venture): The session wasn't closed, need to verify. Could call |
| 44 | // public GetHandler method. |
| 45 | } |
| 46 | |
| 47 | TEST(ManagerCloseTest, CloseSessionFoundAndHandlerReturnsSuccess) |
| 48 | { |
| 49 | // The handler was found and returned success. |
| 50 | |
| 51 | BlobManager mgr; |
| 52 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 53 | auto m1ptr = m1.get(); |
| 54 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 55 | |
| 56 | uint16_t flags = OpenFlags::read, sess; |
| 57 | std::string path = "/asdf/asdf"; |
| 58 | |
| 59 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 60 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 61 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 62 | |
| 63 | EXPECT_CALL(*m1ptr, close(sess)).WillOnce(Return(true)); |
| 64 | |
| 65 | EXPECT_TRUE(mgr.close(sess)); |
| 66 | } |
| 67 | } // namespace blobs |