Kun Yi | 38146a0 | 2018-12-18 21:54:26 -0800 | [diff] [blame^] | 1 | #include "handler_unittest.hpp" |
| 2 | |
| 3 | using ::testing::_; |
| 4 | using ::testing::Return; |
| 5 | using ::testing::StartsWith; |
| 6 | |
| 7 | using namespace std::string_literals; |
| 8 | using namespace binstore; |
| 9 | |
| 10 | namespace blobs |
| 11 | { |
| 12 | |
| 13 | TEST_F(BinaryStoreBlobHandlerOpenTest, FailWhenCannotHandleId) |
| 14 | { |
| 15 | uint16_t flags = OpenFlags::read, sessionId = 0; |
| 16 | EXPECT_FALSE(handler.open(sessionId, flags, "/invalid/blob"s)); |
| 17 | } |
| 18 | |
| 19 | TEST_F(BinaryStoreBlobHandlerOpenTest, FailWhenStoreOpenReturnsFailure) |
| 20 | { |
| 21 | auto testBaseId = "/test/"s; |
| 22 | auto testBlobId = "/test/blob0"s; |
| 23 | uint16_t flags = OpenFlags::read, sessionId = 0; |
| 24 | auto bstore = std::make_unique<MockBinaryStore>(); |
| 25 | |
| 26 | EXPECT_CALL(*bstore, getBaseBlobId()).WillRepeatedly(Return(testBaseId)); |
| 27 | EXPECT_CALL(*bstore, canHandleBlob(StartsWith(testBaseId))) |
| 28 | .WillRepeatedly(Return(true)); |
| 29 | EXPECT_CALL(*bstore, openOrCreateBlob(_, flags)).WillOnce(Return(false)); |
| 30 | |
| 31 | handler.addNewBinaryStore(std::move(bstore)); |
| 32 | |
| 33 | EXPECT_FALSE(handler.open(sessionId, flags, testBlobId)); |
| 34 | } |
| 35 | |
| 36 | TEST_F(BinaryStoreBlobHandlerOpenTest, SucceedWhenStoreOpenReturnsTrue) |
| 37 | { |
| 38 | auto testBaseId = "/test/"s; |
| 39 | auto testBlobId = "/test/blob0"s; |
| 40 | uint16_t flags = OpenFlags::read, sessionId = 0; |
| 41 | auto bstore = std::make_unique<MockBinaryStore>(); |
| 42 | |
| 43 | EXPECT_CALL(*bstore, getBaseBlobId()).WillRepeatedly(Return(testBaseId)); |
| 44 | EXPECT_CALL(*bstore, canHandleBlob(StartsWith(testBaseId))) |
| 45 | .WillRepeatedly(Return(true)); |
| 46 | EXPECT_CALL(*bstore, openOrCreateBlob(_, flags)).WillOnce(Return(true)); |
| 47 | |
| 48 | handler.addNewBinaryStore(std::move(bstore)); |
| 49 | |
| 50 | EXPECT_TRUE(handler.open(sessionId, flags, testBlobId)); |
| 51 | } |
| 52 | |
| 53 | } // namespace blobs |