blob: 5aa2baa618bf9fd29f3dbb061a50c30e974badad [file] [log] [blame]
Patrick Venture3e9899d2019-06-06 10:37:32 -07001/**
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
13namespace ipmi_flash
14{
15namespace
16{
17
18using ::testing::UnorderedElementsAreArray;
19
20class 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
68TEST_F(FirmwareHandlerNotYetStartedUbitTest,
69 OpeningTarballMovesToUploadInProgress)
70{
71 expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
72
Patrick Venture9a69f732019-06-17 14:05:13 -070073 EXPECT_THAT(handler->getBlobIds(),
74 UnorderedElementsAreArray({hashBlobId, ubiTarballBlobId}));
Patrick Venture3e9899d2019-06-06 10:37:32 -070075
76 openToInProgress(ubiTarballBlobId);
Patrick Venture9a69f732019-06-17 14:05:13 -070077 EXPECT_THAT(handler->getBlobIds(),
78 UnorderedElementsAreArray(
79 {hashBlobId, ubiTarballBlobId, activeImageBlobId}));
Patrick Venture3e9899d2019-06-06 10:37:32 -070080}
81
82} // namespace
83} // namespace ipmi_flash