Patrick Venture | 3e9899d | 2019-06-06 10:37:32 -0700 | [diff] [blame] | 1 | /** |
| 2 | * The goal of these tests is to verify opening the ubi tarball changes state |
| 3 | * as expected and does not regress. |
| 4 | */ |
| 5 | #include "firmware_handler.hpp" |
| 6 | #include "firmware_unittest.hpp" |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <gtest/gtest.h> |
| 12 | |
| 13 | namespace ipmi_flash |
| 14 | { |
| 15 | namespace |
| 16 | { |
| 17 | |
| 18 | using ::testing::UnorderedElementsAreArray; |
| 19 | |
| 20 | class FirmwareHandlerNotYetStartedUbitTest : public ::testing::Test |
| 21 | { |
| 22 | protected: |
| 23 | void SetUp() override |
| 24 | { |
| 25 | blobs = { |
| 26 | {hashBlobId, &imageMock}, |
| 27 | {ubiTarballBlobId, &imageMock}, |
| 28 | }; |
| 29 | |
| 30 | std::unique_ptr<TriggerableActionInterface> verifyMock = |
| 31 | std::make_unique<TriggerMock>(); |
| 32 | verifyMockPtr = reinterpret_cast<TriggerMock*>(verifyMock.get()); |
| 33 | |
| 34 | std::unique_ptr<TriggerableActionInterface> updateMock = |
| 35 | std::make_unique<TriggerMock>(); |
| 36 | updateMockPtr = reinterpret_cast<TriggerMock*>(updateMock.get()); |
| 37 | |
| 38 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 39 | blobs, data, std::move(verifyMock), std::move(updateMock)); |
| 40 | } |
| 41 | |
| 42 | void expectedState(FirmwareBlobHandler::UpdateState state) |
| 43 | { |
| 44 | auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get()); |
| 45 | EXPECT_EQ(state, realHandler->getCurrentState()); |
| 46 | } |
| 47 | |
| 48 | void openToInProgress(const std::string& blobId) |
| 49 | { |
| 50 | EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true)); |
| 51 | EXPECT_TRUE(handler->open(session, flags, blobId)); |
| 52 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
| 53 | } |
| 54 | |
| 55 | ImageHandlerMock imageMock; |
| 56 | std::vector<HandlerPack> blobs; |
| 57 | std::vector<DataHandlerPack> data = { |
| 58 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}}; |
| 59 | std::unique_ptr<blobs::GenericBlobInterface> handler; |
| 60 | TriggerMock* verifyMockPtr; |
| 61 | TriggerMock* updateMockPtr; |
| 62 | |
| 63 | std::uint16_t session = 1; |
| 64 | std::uint16_t flags = |
| 65 | blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi; |
| 66 | }; |
| 67 | |
| 68 | TEST_F(FirmwareHandlerNotYetStartedUbitTest, |
| 69 | OpeningTarballMovesToUploadInProgress) |
| 70 | { |
| 71 | expectedState(FirmwareBlobHandler::UpdateState::notYetStarted); |
| 72 | |
Patrick Venture | 9a69f73 | 2019-06-17 14:05:13 -0700 | [diff] [blame] | 73 | EXPECT_THAT(handler->getBlobIds(), |
| 74 | UnorderedElementsAreArray({hashBlobId, ubiTarballBlobId})); |
Patrick Venture | 3e9899d | 2019-06-06 10:37:32 -0700 | [diff] [blame] | 75 | |
| 76 | openToInProgress(ubiTarballBlobId); |
Patrick Venture | 9a69f73 | 2019-06-17 14:05:13 -0700 | [diff] [blame] | 77 | EXPECT_THAT(handler->getBlobIds(), |
| 78 | UnorderedElementsAreArray( |
| 79 | {hashBlobId, ubiTarballBlobId, activeImageBlobId})); |
Patrick Venture | 3e9899d | 2019-06-06 10:37:32 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | } // namespace |
| 83 | } // namespace ipmi_flash |