blob: 0f49494ba2d02859473500e63f9f1073fdc4ccce [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
Patrick Venture9b534f02018-12-13 16:10:02 -08009namespace host_tool
10{
11
Patrick Ventureaa32a362018-12-13 10:52:33 -080012using ::testing::Eq;
13using ::testing::Return;
14using ::testing::StrEq;
15
16TEST(UpdaterTest, NormalWalkthroughAllHappy)
17{
18 /* Call updaterMain and have everything respond happily. */
19 DataInterfaceMock handlerMock;
20 BlobInterfaceMock blobMock;
21 std::string firmwareImage = "image.bin";
22 std::string signatureFile = "image.sig";
Patrick Venture339dece2018-12-14 18:32:04 -080023 std::string expectedBlob = "/flash/image";
Patrick Ventureaa32a362018-12-13 10:52:33 -080024
Patrick Venture339dece2018-12-14 18:32:04 -080025 std::vector<std::string> blobList = {expectedBlob};
Patrick Ventureaa32a362018-12-13 10:52:33 -080026 StatResponse statObj;
27 statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
28 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
29 statObj.size = 0;
30 blobs::FirmwareBlobHandler::UpdateFlags supported =
31 blobs::FirmwareBlobHandler::UpdateFlags::lpc;
32 std::uint16_t session = 0xbeef;
33
34 EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
35
Patrick Venture339dece2018-12-14 18:32:04 -080036 EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj));
Patrick Ventureaa32a362018-12-13 10:52:33 -080037
38 EXPECT_CALL(handlerMock, supportedType()).WillOnce(Return(supported));
39
Patrick Venture339dece2018-12-14 18:32:04 -080040 EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
Patrick Ventureaa32a362018-12-13 10:52:33 -080041 .WillOnce(Return(session));
42
43 EXPECT_CALL(handlerMock,
44 sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
45 .WillOnce(Return(true));
46
47 updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
48}
Patrick Venture9b534f02018-12-13 16:10:02 -080049
50} // namespace host_tool