Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 1 | #include "cleanup.hpp" |
| 2 | #include "filesystem_mock.hpp" |
| 3 | #include "util.hpp" |
| 4 | |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame^] | 5 | #include <memory> |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | namespace ipmi_flash |
| 12 | { |
| 13 | namespace |
| 14 | { |
| 15 | |
| 16 | using ::testing::Return; |
| 17 | using ::testing::UnorderedElementsAreArray; |
| 18 | |
| 19 | class CleanupHandlerTest : public ::testing::Test |
| 20 | { |
| 21 | protected: |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame^] | 22 | CleanupHandlerTest() : mock(std::make_unique<FileSystemMock>()) |
| 23 | { |
| 24 | mock_ptr = mock.get(); |
| 25 | handler = std::make_unique<FileCleanupHandler>(cleanupBlobId, blobs, |
| 26 | std::move(mock)); |
| 27 | } |
| 28 | |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 29 | std::vector<std::string> blobs = {"abcd", "efgh"}; |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame^] | 30 | std::unique_ptr<FileSystemMock> mock; |
| 31 | FileSystemMock* mock_ptr; |
| 32 | std::unique_ptr<FileCleanupHandler> handler; |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | TEST_F(CleanupHandlerTest, GetBlobListReturnsExpectedList) |
| 36 | { |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame^] | 37 | EXPECT_TRUE(handler->canHandleBlob(cleanupBlobId)); |
| 38 | EXPECT_THAT(handler->getBlobIds(), |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 39 | UnorderedElementsAreArray({cleanupBlobId})); |
| 40 | } |
| 41 | |
| 42 | TEST_F(CleanupHandlerTest, CommitShouldDeleteFiles) |
| 43 | { |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame^] | 44 | EXPECT_CALL(*mock_ptr, remove("abcd")).WillOnce(Return()); |
| 45 | EXPECT_CALL(*mock_ptr, remove("efgh")).WillOnce(Return()); |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 46 | |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame^] | 47 | EXPECT_TRUE(handler->commit(1, {})); |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | } // namespace |
| 51 | } // namespace ipmi_flash |