Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 1 | #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 | |
| 9 | using ::testing::Eq; |
| 10 | using ::testing::Return; |
| 11 | using ::testing::StrEq; |
| 12 | |
| 13 | TEST(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 Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 20 | std::string expectedBlob = "/flash/image"; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 21 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 22 | std::vector<std::string> blobList = {expectedBlob}; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 23 | 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 Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 33 | EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj)); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 34 | |
| 35 | EXPECT_CALL(handlerMock, supportedType()).WillOnce(Return(supported)); |
| 36 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 37 | EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported))) |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 38 | .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 | } |