xref: /openbmc/estoraged/src/test/include/estoraged_test.hpp (revision 530ce1e82b9cc606a19fc99cb8d31e1410f401f2)
1 
2 #include "cryptErase.hpp"
3 #include "cryptsetupInterface.hpp"
4 #include "estoraged.hpp"
5 #include "filesystemInterface.hpp"
6 
7 #include <unistd.h>
8 
9 #include <exception>
10 #include <filesystem>
11 #include <initializer_list>
12 #include <string>
13 
14 #include <gmock/gmock.h>
15 #include <gtest/gtest.h>
16 
17 namespace estoraged_test
18 {
19 
20 class MockFilesystemInterface : public estoraged::FilesystemInterface
21 {
22   public:
23     MOCK_METHOD(int, runMkfs,
24                 (const std::string& logicalVolumePath,
25                  std::initializer_list<std::string> options),
26                 (override));
27 
28     MOCK_METHOD(int, doMount,
29                 (const char* source, const char* target,
30                  const char* filesystemtype, unsigned long mountflags,
31                  const void* data),
32                 (override));
33 
34     MOCK_METHOD(int, doUnmount, (const char* target), (override));
35 
36     MOCK_METHOD(bool, createDirectory, (const std::filesystem::path& p),
37                 (override));
38 
39     MOCK_METHOD(bool, removeDirectory, (const std::filesystem::path& p),
40                 (override));
41 
42     MOCK_METHOD(bool, directoryExists, (const std::filesystem::path& p),
43                 (override));
44 
45     MOCK_METHOD(int, runFsck,
46                 (const std::string& logicalVolumePath,
47                  const std::string& options),
48                 (override));
49 };
50 
51 class MockCryptsetupInterface : public estoraged::CryptsetupInterface
52 {
53   public:
54     MOCK_METHOD(int, cryptFormat,
55                 (struct crypt_device * cd, const char* type, const char* cipher,
56                  const char* cipherMode, const char* uuid,
57                  const char* volumeKey, size_t volumeKeySize, void* params),
58                 (override));
59 
60     MOCK_METHOD(int, cryptKeyslotAddByVolumeKey,
61                 (struct crypt_device * cd, int keyslot, const char* volumeKey,
62                  size_t volumeKeySize, const char* passphrase,
63                  size_t passphraseSize),
64                 (override));
65 
66     MOCK_METHOD(int, cryptLoad,
67                 (struct crypt_device * cd, const char* requestedType,
68                  void* params),
69                 (override));
70 
71     MOCK_METHOD(int, cryptKeyslotChangeByPassphrase,
72                 (struct crypt_device * cd, int keyslotOld, int keyslotNew,
73                  const char* passphrase, size_t passphraseSize,
74                  const char* newPassphrase, size_t newPassphraseSize),
75                 (override));
76 
77     MOCK_METHOD(int, cryptActivateByPassphrase,
78                 (struct crypt_device * cd, const char* name, int keyslot,
79                  const char* passphrase, size_t passphraseSize, uint32_t flags),
80                 (override));
81 
82     MOCK_METHOD(int, cryptDeactivate,
83                 (struct crypt_device * cd, const char* name), (override));
84 
85     MOCK_METHOD(int, cryptKeyslotDestroy,
86                 (struct crypt_device * cd, const int slot), (override));
87 
88     MOCK_METHOD(int, cryptKeySlotMax, (const char* type), (override));
89 
90     MOCK_METHOD(crypt_keyslot_info, cryptKeySlotStatus,
91                 (struct crypt_device * cd, int keyslot), (override));
92 
93     MOCK_METHOD(std::string, cryptGetDir, (), (override));
94 };
95 
96 } // namespace estoraged_test
97