Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 1 | #include "firmware_handler.hpp" |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 2 | #include "flags.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 3 | #include "image_mock.hpp" |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 4 | #include "triggerable_mock.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 5 | #include "util.hpp" |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 6 | |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 7 | #include <algorithm> |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 8 | #include <memory> |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 9 | #include <vector> |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 10 | |
| 11 | #include <gtest/gtest.h> |
| 12 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 13 | namespace ipmi_flash |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 14 | { |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 15 | namespace |
| 16 | { |
| 17 | |
| 18 | using ::testing::UnorderedElementsAreArray; |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 19 | |
| 20 | TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails) |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 21 | { |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 22 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 23 | {FirmwareFlags::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 24 | }; |
| 25 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 26 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 27 | {}, data, std::move(CreateActionMap("abcd"))); |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 28 | EXPECT_EQ(handler, nullptr); |
| 29 | } |
| 30 | TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails) |
| 31 | { |
| 32 | ImageHandlerMock imageMock; |
| 33 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 34 | std::vector<HandlerPack> blobs; |
| 35 | blobs.push_back(std::move( |
| 36 | HandlerPack(hashBlobId, std::make_unique<ImageHandlerMock>()))); |
| 37 | blobs.push_back( |
| 38 | std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>()))); |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 39 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 40 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 41 | std::move(blobs), {}, std::move(CreateActionMap("asdf"))); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 42 | EXPECT_EQ(handler, nullptr); |
| 43 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 44 | TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness) |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 45 | { |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 46 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 47 | {FirmwareFlags::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 48 | }; |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 49 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 50 | /* This works fine only if you also pass in the hash handler. */ |
| 51 | std::vector<HandlerPack> blobs; |
| 52 | blobs.push_back( |
| 53 | std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>()))); |
| 54 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 55 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 56 | std::move(blobs), data, std::move(CreateActionMap("asdf"))); |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 57 | EXPECT_EQ(handler, nullptr); |
| 58 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 59 | std::vector<HandlerPack> blobs2; |
| 60 | blobs2.push_back( |
| 61 | std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>()))); |
| 62 | blobs2.push_back(std::move( |
| 63 | HandlerPack(hashBlobId, std::make_unique<ImageHandlerMock>()))); |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 64 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 65 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame^] | 66 | std::move(blobs2), data, std::move(CreateActionMap("asdf"))); |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 67 | |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 68 | auto result = handler->getBlobIds(); |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 69 | std::vector<std::string> expectedBlobs = {"asdf", hashBlobId}; |
| 70 | EXPECT_THAT(result, UnorderedElementsAreArray(expectedBlobs)); |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 71 | } |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 72 | |
| 73 | } // namespace |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 74 | } // namespace ipmi_flash |