Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 1 | #include "data_mock.hpp" |
| 2 | #include "firmware_handler.hpp" |
| 3 | #include "image_mock.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 4 | #include "util.hpp" |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 5 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 6 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
| 9 | #include <gmock/gmock.h> |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | namespace blobs |
| 13 | { |
| 14 | using ::testing::Eq; |
| 15 | using ::testing::Return; |
| 16 | using ::testing::StrEq; |
| 17 | |
| 18 | TEST(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds) |
| 19 | { |
| 20 | /* Delete active image succeeds. */ |
| 21 | DataHandlerMock dataMock; |
| 22 | ImageHandlerMock imageMock; |
| 23 | |
| 24 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 25 | {hashBlobId, &imageMock}, |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 26 | {"asdf", &imageMock}, |
| 27 | }; |
| 28 | std::vector<DataHandlerPack> data = { |
| 29 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 30 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
| 31 | }; |
| 32 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 33 | sdbusplus::SdBusMock sdbus_mock; |
| 34 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 35 | |
| 36 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 37 | std::move(bus_mock), blobs, data); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 38 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 39 | EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 40 | |
| 41 | EXPECT_TRUE(handler->open( |
| 42 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 43 | hashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 44 | |
| 45 | /* The active hash blob_id was added. */ |
| 46 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 47 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 48 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 49 | activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 50 | |
| 51 | /* Set up close() expectations. */ |
| 52 | EXPECT_CALL(imageMock, close()); |
| 53 | EXPECT_TRUE(handler->close(0)); |
| 54 | |
| 55 | currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 56 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 57 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 58 | activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 59 | |
| 60 | /* Delete the blob. */ |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 61 | EXPECT_TRUE(handler->deleteBlob(activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 62 | |
| 63 | currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 64 | EXPECT_EQ(3, currentBlobs.size()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 65 | EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame^] | 66 | activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } // namespace blobs |