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 | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 5 | #include "verification_mock.hpp" |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 6 | |
| 7 | #include <vector> |
| 8 | |
| 9 | #include <gmock/gmock.h> |
| 10 | #include <gtest/gtest.h> |
| 11 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 12 | namespace ipmi_flash |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 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 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 34 | blobs, data, CreateVerifyMock()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 35 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 36 | EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 37 | |
| 38 | EXPECT_TRUE(handler->open( |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 39 | 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 40 | hashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 41 | |
| 42 | /* The active hash blob_id was added. */ |
| 43 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 44 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 45 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 46 | activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 47 | |
| 48 | /* Set up close() expectations. */ |
| 49 | EXPECT_CALL(imageMock, close()); |
| 50 | EXPECT_TRUE(handler->close(0)); |
| 51 | |
| 52 | currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 53 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 54 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 55 | activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 56 | |
| 57 | /* Delete the blob. */ |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 58 | EXPECT_TRUE(handler->deleteBlob(activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 59 | |
| 60 | currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 61 | EXPECT_EQ(3, currentBlobs.size()); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 62 | EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 63 | activeHashBlobId)); |
Patrick Venture | 9e5aab2 | 2018-11-09 20:49:28 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 66 | } // namespace ipmi_flash |