blob: bc7417c0136aedebbbd24f5165c68c919d6aa66f [file] [log] [blame]
Patrick Ventureaa32a362018-12-13 10:52:33 -08001#include "blob_interface_mock.hpp"
2#include "data_interface_mock.hpp"
3#include "updater.hpp"
4
5#include <string>
6
7#include <gtest/gtest.h>
8
9using ::testing::Eq;
10using ::testing::Return;
11using ::testing::StrEq;
12
13TEST(UpdaterTest, NormalWalkthroughAllHappy)
14{
15 /* Call updaterMain and have everything respond happily. */
16 DataInterfaceMock handlerMock;
17 BlobInterfaceMock blobMock;
18 std::string firmwareImage = "image.bin";
19 std::string signatureFile = "image.sig";
Patrick Venture339dece2018-12-14 18:32:04 -080020 std::string expectedBlob = "/flash/image";
Patrick Ventureaa32a362018-12-13 10:52:33 -080021
Patrick Venture339dece2018-12-14 18:32:04 -080022 std::vector<std::string> blobList = {expectedBlob};
Patrick Ventureaa32a362018-12-13 10:52:33 -080023 StatResponse statObj;
24 statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
25 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
26 statObj.size = 0;
27 blobs::FirmwareBlobHandler::UpdateFlags supported =
28 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
29 std::uint16_t session = 0xbeef;
30
31 EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
32
Patrick Venture339dece2018-12-14 18:32:04 -080033 EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj));
Patrick Ventureaa32a362018-12-13 10:52:33 -080034
35 EXPECT_CALL(handlerMock, supportedType()).WillOnce(Return(supported));
36
Patrick Venture339dece2018-12-14 18:32:04 -080037 EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
Patrick Ventureaa32a362018-12-13 10:52:33 -080038 .WillOnce(Return(session));
39
40 EXPECT_CALL(handlerMock,
41 sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
42 .WillOnce(Return(true));
43
44 updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
45}