blob: 9360dd3bd902724287c236dd5b10138c301a8513 [file] [log] [blame]
Kun Yi68c81142018-12-18 11:17:14 -08001#pragma once
2
3#include "binarystore.hpp"
Patrick Venture15f0f942020-07-09 09:38:18 -07004#include "binarystore_interface.hpp"
Kun Yi2765b642019-01-16 11:11:24 -08005#include "sys_file.hpp"
Kun Yi68c81142018-12-18 11:17:14 -08006
Patrick Venture15f0f942020-07-09 09:38:18 -07007#include <memory>
Willy Tu67391d52021-12-07 19:53:49 -08008#include <optional>
Patrick Venture15f0f942020-07-09 09:38:18 -07009#include <string>
10#include <vector>
11
Kun Yi68c81142018-12-18 11:17:14 -080012#include <gmock/gmock.h>
13
Kun Yi64dc05c2018-12-19 13:19:03 -080014using ::testing::Invoke;
15
Kun Yi68c81142018-12-18 11:17:14 -080016namespace binstore
17{
18
19class MockBinaryStore : public BinaryStoreInterface
20{
21 public:
Kun Yi2765b642019-01-16 11:11:24 -080022 MockBinaryStore(const std::string& baseBlobId,
Willy Tu67391d52021-12-07 19:53:49 -080023 std::unique_ptr<SysFile> file,
24 std::optional<uint32_t> maxSize = std::nullopt) :
25 real_store_(baseBlobId, std::move(file), maxSize)
Kun Yi64dc05c2018-12-19 13:19:03 -080026 {
27 // Implemented calls in BinaryStore will be directed to the real object.
28 ON_CALL(*this, getBaseBlobId)
29 .WillByDefault(Invoke(&real_store_, &BinaryStore::getBaseBlobId));
30 ON_CALL(*this, getBlobIds)
31 .WillByDefault(Invoke(&real_store_, &BinaryStore::getBlobIds));
Kun Yi6baa7132019-01-08 21:21:02 -080032 ON_CALL(*this, openOrCreateBlob)
33 .WillByDefault(
34 Invoke(&real_store_, &BinaryStore::openOrCreateBlob));
35 ON_CALL(*this, close)
36 .WillByDefault(Invoke(&real_store_, &BinaryStore::close));
Kun Yi6967b772019-02-22 13:48:12 -080037 ON_CALL(*this, read)
38 .WillByDefault(Invoke(&real_store_, &BinaryStore::read));
39 ON_CALL(*this, write)
40 .WillByDefault(Invoke(&real_store_, &BinaryStore::write));
Kun Yid297c9f2019-01-09 13:52:30 -080041 ON_CALL(*this, commit)
42 .WillByDefault(Invoke(&real_store_, &BinaryStore::commit));
Kun Yi1a25e0d2020-05-11 12:28:53 -070043 ON_CALL(*this, stat)
44 .WillByDefault(Invoke(&real_store_, &BinaryStore::stat));
Kun Yi64dc05c2018-12-19 13:19:03 -080045 }
Kun Yi68c81142018-12-18 11:17:14 -080046 MOCK_CONST_METHOD0(getBaseBlobId, std::string());
Kun Yi68c81142018-12-18 11:17:14 -080047 MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>());
Kun Yi38146a02018-12-18 21:54:26 -080048 MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t));
Kun Yic0adbc32018-12-18 22:35:29 -080049 MOCK_METHOD1(deleteBlob, bool(const std::string&));
Kun Yi68c81142018-12-18 11:17:14 -080050 MOCK_METHOD2(read, std::vector<uint8_t>(uint32_t, uint32_t));
51 MOCK_METHOD2(write, bool(uint32_t, const std::vector<uint8_t>&));
52 MOCK_METHOD0(commit, bool());
53 MOCK_METHOD0(close, bool());
Kun Yi1a25e0d2020-05-11 12:28:53 -070054 MOCK_METHOD1(stat, bool(blobs::BlobMeta* meta));
Kun Yi64dc05c2018-12-19 13:19:03 -080055
Maksym Sloykoeb274112021-10-27 23:48:32 +000056 std::vector<uint8_t> readBlob(const std::string& blobId) const override
57 {
58 return real_store_.readBlob(blobId);
59 }
60
Kun Yi64dc05c2018-12-19 13:19:03 -080061 private:
62 BinaryStore real_store_;
Kun Yi68c81142018-12-18 11:17:14 -080063};
64
65} // namespace binstore