19efef5d9SPatrick Venture #include "cleanup.hpp"
29efef5d9SPatrick Venture #include "filesystem_mock.hpp"
39efef5d9SPatrick Venture #include "util.hpp"
49efef5d9SPatrick Venture
5*48474bc1SPatrick Venture #include <blobs-ipmid/blobs.hpp>
6*48474bc1SPatrick Venture
7*48474bc1SPatrick Venture #include <cstdint>
82950c258SPatrick Venture #include <memory>
99efef5d9SPatrick Venture #include <string>
109efef5d9SPatrick Venture #include <vector>
119efef5d9SPatrick Venture
129efef5d9SPatrick Venture #include <gtest/gtest.h>
139efef5d9SPatrick Venture
149efef5d9SPatrick Venture namespace ipmi_flash
159efef5d9SPatrick Venture {
169efef5d9SPatrick Venture namespace
179efef5d9SPatrick Venture {
189efef5d9SPatrick Venture
199efef5d9SPatrick Venture using ::testing::Return;
209efef5d9SPatrick Venture using ::testing::UnorderedElementsAreArray;
219efef5d9SPatrick Venture
229efef5d9SPatrick Venture class CleanupHandlerTest : public ::testing::Test
239efef5d9SPatrick Venture {
249efef5d9SPatrick Venture protected:
CleanupHandlerTest()252950c258SPatrick Venture CleanupHandlerTest() : mock(std::make_unique<FileSystemMock>())
262950c258SPatrick Venture {
272950c258SPatrick Venture mock_ptr = mock.get();
282950c258SPatrick Venture handler = std::make_unique<FileCleanupHandler>(cleanupBlobId, blobs,
292950c258SPatrick Venture std::move(mock));
302950c258SPatrick Venture }
312950c258SPatrick Venture
329efef5d9SPatrick Venture std::vector<std::string> blobs = {"abcd", "efgh"};
332950c258SPatrick Venture std::unique_ptr<FileSystemMock> mock;
342950c258SPatrick Venture FileSystemMock* mock_ptr;
352950c258SPatrick Venture std::unique_ptr<FileCleanupHandler> handler;
369efef5d9SPatrick Venture };
379efef5d9SPatrick Venture
TEST_F(CleanupHandlerTest,GetBlobListReturnsExpectedList)389efef5d9SPatrick Venture TEST_F(CleanupHandlerTest, GetBlobListReturnsExpectedList)
399efef5d9SPatrick Venture {
402950c258SPatrick Venture EXPECT_TRUE(handler->canHandleBlob(cleanupBlobId));
412950c258SPatrick Venture EXPECT_THAT(handler->getBlobIds(),
429efef5d9SPatrick Venture UnorderedElementsAreArray({cleanupBlobId}));
439efef5d9SPatrick Venture }
449efef5d9SPatrick Venture
TEST_F(CleanupHandlerTest,CommitShouldDeleteFiles)459efef5d9SPatrick Venture TEST_F(CleanupHandlerTest, CommitShouldDeleteFiles)
469efef5d9SPatrick Venture {
472950c258SPatrick Venture EXPECT_CALL(*mock_ptr, remove("abcd")).WillOnce(Return());
482950c258SPatrick Venture EXPECT_CALL(*mock_ptr, remove("efgh")).WillOnce(Return());
499efef5d9SPatrick Venture
502950c258SPatrick Venture EXPECT_TRUE(handler->commit(1, {}));
519efef5d9SPatrick Venture }
529efef5d9SPatrick Venture
TEST_F(CleanupHandlerTest,VerifyDefaultBlobMethods)53*48474bc1SPatrick Venture TEST_F(CleanupHandlerTest, VerifyDefaultBlobMethods)
54*48474bc1SPatrick Venture {
55*48474bc1SPatrick Venture // Test each of the blob handler commands.
56*48474bc1SPatrick Venture EXPECT_TRUE(handler->open(/*session*/ 0, /*flags*/ 0, "abcd"));
57*48474bc1SPatrick Venture EXPECT_TRUE(handler->close(/*session*/ 0));
58*48474bc1SPatrick Venture EXPECT_TRUE(handler->expire(/*session*/ 0));
59*48474bc1SPatrick Venture EXPECT_FALSE(handler->deleteBlob("abcd"));
60*48474bc1SPatrick Venture
61*48474bc1SPatrick Venture blobs::BlobMeta meta;
62*48474bc1SPatrick Venture EXPECT_FALSE(handler->stat("abcd", &meta));
63*48474bc1SPatrick Venture EXPECT_FALSE(handler->stat(/*session*/ 0, &meta));
64*48474bc1SPatrick Venture
65*48474bc1SPatrick Venture EXPECT_THAT(handler->read(/*session*/ 0, /*offset*/ 0, 1),
66*48474bc1SPatrick Venture ::testing::IsEmpty());
67*48474bc1SPatrick Venture
68*48474bc1SPatrick Venture std::vector<uint8_t> data = {0x01};
69*48474bc1SPatrick Venture EXPECT_FALSE(handler->write(/*session*/ 0, /*offset*/ 0, data));
70*48474bc1SPatrick Venture }
71*48474bc1SPatrick Venture
729efef5d9SPatrick Venture } // namespace
739efef5d9SPatrick Venture } // namespace ipmi_flash
74