blob: 33216a9d2f28023509e352a4b2594ec9641bd1e1 [file] [log] [blame]
Patrick Venture9efef5d2019-06-19 08:45:44 -07001#include "cleanup.hpp"
2#include "filesystem_mock.hpp"
3#include "util.hpp"
4
Patrick Venture2950c252020-07-16 15:11:03 -07005#include <memory>
Patrick Venture9efef5d2019-06-19 08:45:44 -07006#include <string>
7#include <vector>
8
9#include <gtest/gtest.h>
10
11namespace ipmi_flash
12{
13namespace
14{
15
16using ::testing::Return;
17using ::testing::UnorderedElementsAreArray;
18
19class CleanupHandlerTest : public ::testing::Test
20{
21 protected:
Patrick Venture2950c252020-07-16 15:11:03 -070022 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 Venture9efef5d2019-06-19 08:45:44 -070029 std::vector<std::string> blobs = {"abcd", "efgh"};
Patrick Venture2950c252020-07-16 15:11:03 -070030 std::unique_ptr<FileSystemMock> mock;
31 FileSystemMock* mock_ptr;
32 std::unique_ptr<FileCleanupHandler> handler;
Patrick Venture9efef5d2019-06-19 08:45:44 -070033};
34
35TEST_F(CleanupHandlerTest, GetBlobListReturnsExpectedList)
36{
Patrick Venture2950c252020-07-16 15:11:03 -070037 EXPECT_TRUE(handler->canHandleBlob(cleanupBlobId));
38 EXPECT_THAT(handler->getBlobIds(),
Patrick Venture9efef5d2019-06-19 08:45:44 -070039 UnorderedElementsAreArray({cleanupBlobId}));
40}
41
42TEST_F(CleanupHandlerTest, CommitShouldDeleteFiles)
43{
Patrick Venture2950c252020-07-16 15:11:03 -070044 EXPECT_CALL(*mock_ptr, remove("abcd")).WillOnce(Return());
45 EXPECT_CALL(*mock_ptr, remove("efgh")).WillOnce(Return());
Patrick Venture9efef5d2019-06-19 08:45:44 -070046
Patrick Venture2950c252020-07-16 15:11:03 -070047 EXPECT_TRUE(handler->commit(1, {}));
Patrick Venture9efef5d2019-06-19 08:45:44 -070048}
49
50} // namespace
51} // namespace ipmi_flash