/** * The goal of these tests is to verify opening the ubi tarball changes state * as expected and does not regress. */ #include "firmware_handler.hpp" #include "firmware_unittest.hpp" #include #include #include #include namespace ipmi_flash { namespace { using ::testing::UnorderedElementsAreArray; class FirmwareHandlerNotYetStartedUbitTest : public ::testing::Test { protected: void SetUp() override { std::unique_ptr image = std::make_unique(); hashImageMock = reinterpret_cast(image.get()); blobs.emplace_back(hashBlobId, std::move(image)); image = std::make_unique(); imageMock = reinterpret_cast(image.get()); blobs.emplace_back(ubiTarballBlobId, std::move(image)); std::unique_ptr verifyMock = std::make_unique(); verifyMockPtr = reinterpret_cast(verifyMock.get()); std::unique_ptr updateMock = std::make_unique(); updateMockPtr = reinterpret_cast(updateMock.get()); std::unique_ptr actionPack = std::make_unique(); actionPack->preparation = CreateTriggerMock(); actionPack->verification = std::move(verifyMock); actionPack->update = std::move(updateMock); ActionMap packs; packs[ubiTarballBlobId] = std::move(actionPack); std::vector data; data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs), std::move(data), std::move(packs)); } void expectedState(FirmwareBlobHandler::UpdateState state) { auto realHandler = dynamic_cast(handler.get()); EXPECT_EQ(state, realHandler->getCurrentState()); } void openToInProgress(const std::string& blobId) { if (blobId == hashBlobId) { EXPECT_CALL(*hashImageMock, open(blobId, std::ios::out)) .WillOnce(Return(true)); } else { EXPECT_CALL(*imageMock, open(blobId, std::ios::out)) .WillOnce(Return(true)); } EXPECT_TRUE(handler->open(session, flags, blobId)); expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); } ImageHandlerMock *hashImageMock, *imageMock; std::vector blobs; std::unique_ptr handler; TriggerMock* verifyMockPtr; TriggerMock* updateMockPtr; std::uint16_t session = 1; std::uint16_t flags = static_cast(blobs::OpenFlags::write) | FirmwareFlags::UpdateFlags::ipmi; }; TEST_F(FirmwareHandlerNotYetStartedUbitTest, OpeningTarballMovesToUploadInProgress) { expectedState(FirmwareBlobHandler::UpdateState::notYetStarted); EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray({hashBlobId, ubiTarballBlobId})); openToInProgress(ubiTarballBlobId); EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray( {hashBlobId, ubiTarballBlobId, activeImageBlobId})); } } // namespace } // namespace ipmi_flash