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 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame^] | 9 | namespace host_tool |
| 10 | { |
| 11 | |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 12 | using ::testing::Eq; |
| 13 | using ::testing::Return; |
| 14 | using ::testing::StrEq; |
| 15 | |
| 16 | TEST(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 Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 23 | std::string expectedBlob = "/flash/image"; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 24 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 25 | std::vector<std::string> blobList = {expectedBlob}; |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 26 | 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 Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 36 | EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj)); |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 37 | |
| 38 | EXPECT_CALL(handlerMock, supportedType()).WillOnce(Return(supported)); |
| 39 | |
Patrick Venture | 339dece | 2018-12-14 18:32:04 -0800 | [diff] [blame] | 40 | EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported))) |
Patrick Venture | aa32a36 | 2018-12-13 10:52:33 -0800 | [diff] [blame] | 41 | .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 Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame^] | 49 | |
| 50 | } // namespace host_tool |