blob: 1d69f2405ade12a29c42ade0fb10620727990bf3 [file] [log] [blame]
Kun Yi38146a02018-12-18 21:54:26 -08001#include "handler_unittest.hpp"
2
3using ::testing::_;
4using ::testing::Return;
5using ::testing::StartsWith;
6
7using namespace std::string_literals;
8using namespace binstore;
9
10namespace blobs
11{
12
13TEST_F(BinaryStoreBlobHandlerOpenTest, FailWhenCannotHandleId)
14{
15 uint16_t flags = OpenFlags::read, sessionId = 0;
16 EXPECT_FALSE(handler.open(sessionId, flags, "/invalid/blob"s));
17}
18
19TEST_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
36TEST_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