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 | #include <vector> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace blobs |
| 8 | { |
| 9 | |
| 10 | using ::testing::_; |
| 11 | using ::testing::Return; |
| 12 | |
| 13 | TEST(ManagerCommitTest, CommitNoSessionReturnsFalse) |
| 14 | { |
| 15 | // Calling Commit on a session that doesn't exist should return false. |
| 16 | |
| 17 | BlobManager mgr; |
| 18 | uint16_t sess = 1; |
| 19 | std::vector<uint8_t> data; |
| 20 | |
| 21 | EXPECT_FALSE(mgr.commit(sess, data)); |
| 22 | } |
| 23 | |
| 24 | TEST(ManagerCommitTest, CommitSessionFoundButHandlerReturnsFalse) |
| 25 | { |
| 26 | // The handler was found but it returned failure. |
| 27 | |
| 28 | BlobManager mgr; |
| 29 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 30 | auto m1ptr = m1.get(); |
| 31 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 32 | |
| 33 | uint16_t flags = OpenFlags::write, sess; |
| 34 | std::string path = "/asdf/asdf"; |
| 35 | |
| 36 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 37 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 38 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 39 | |
| 40 | std::vector<uint8_t> data; |
| 41 | EXPECT_CALL(*m1ptr, commit(sess, data)).WillOnce(Return(false)); |
| 42 | |
| 43 | EXPECT_FALSE(mgr.commit(sess, data)); |
| 44 | } |
| 45 | |
| 46 | TEST(ManagerCommitTest, CommitSessionFoundAndHandlerReturnsSuccess) |
| 47 | { |
| 48 | // The handler was found and returned success. |
| 49 | |
| 50 | BlobManager mgr; |
| 51 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 52 | auto m1ptr = m1.get(); |
| 53 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 54 | |
| 55 | uint16_t flags = OpenFlags::write, sess; |
| 56 | std::string path = "/asdf/asdf"; |
| 57 | |
| 58 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 59 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 60 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 61 | |
| 62 | std::vector<uint8_t> data; |
| 63 | EXPECT_CALL(*m1ptr, commit(sess, data)).WillOnce(Return(true)); |
| 64 | |
| 65 | EXPECT_TRUE(mgr.commit(sess, data)); |
| 66 | } |
| 67 | } // namespace blobs |