1 #include "cleanup.hpp"
2 #include "filesystem_mock.hpp"
3 #include "util.hpp"
4 
5 #include <string>
6 #include <vector>
7 
8 #include <gtest/gtest.h>
9 
10 namespace ipmi_flash
11 {
12 namespace
13 {
14 
15 using ::testing::Return;
16 using ::testing::UnorderedElementsAreArray;
17 
18 class CleanupHandlerTest : public ::testing::Test
19 {
20   protected:
21     std::vector<std::string> blobs = {"abcd", "efgh"};
22     FileSystemMock mock;
23     FileCleanupHandler handler{cleanupBlobId, blobs, &mock};
24 };
25 
26 TEST_F(CleanupHandlerTest, GetBlobListReturnsExpectedList)
27 {
28     EXPECT_TRUE(handler.canHandleBlob(cleanupBlobId));
29     EXPECT_THAT(handler.getBlobIds(),
30                 UnorderedElementsAreArray({cleanupBlobId}));
31 }
32 
33 TEST_F(CleanupHandlerTest, CommitShouldDeleteFiles)
34 {
35     EXPECT_CALL(mock, remove("abcd")).WillOnce(Return());
36     EXPECT_CALL(mock, remove("efgh")).WillOnce(Return());
37 
38     EXPECT_TRUE(handler.commit(1, {}));
39 }
40 
41 } // namespace
42 } // namespace ipmi_flash
43