tools: add missing updater unit-tests
Add missing updater unit-tests to prevent regressions moving forward in
development.
Change-Id: I33c8052fc62cd645059bcba6c5111063e4348e0c
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/tools_updater_unittest.cpp b/test/tools_updater_unittest.cpp
new file mode 100644
index 0000000..d36304b
--- /dev/null
+++ b/test/tools_updater_unittest.cpp
@@ -0,0 +1,45 @@
+#include "blob_interface_mock.hpp"
+#include "data_interface_mock.hpp"
+#include "updater.hpp"
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+using ::testing::Eq;
+using ::testing::Return;
+using ::testing::StrEq;
+
+TEST(UpdaterTest, NormalWalkthroughAllHappy)
+{
+ /* Call updaterMain and have everything respond happily. */
+ DataInterfaceMock handlerMock;
+ BlobInterfaceMock blobMock;
+ std::string firmwareImage = "image.bin";
+ std::string signatureFile = "image.sig";
+
+ std::vector<std::string> blobList = {"/flash/image"};
+ StatResponse statObj;
+ statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
+ blobs::FirmwareBlobHandler::UpdateFlags::lpc;
+ statObj.size = 0;
+ blobs::FirmwareBlobHandler::UpdateFlags supported =
+ blobs::FirmwareBlobHandler::UpdateFlags::lpc;
+ std::uint16_t session = 0xbeef;
+
+ EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
+
+ EXPECT_CALL(blobMock, getStat(StrEq(blobList[0].c_str())))
+ .WillOnce(Return(statObj));
+
+ EXPECT_CALL(handlerMock, supportedType()).WillOnce(Return(supported));
+
+ EXPECT_CALL(blobMock, openBlob(StrEq(blobList[0].c_str()), Eq(supported)))
+ .WillOnce(Return(session));
+
+ EXPECT_CALL(handlerMock,
+ sendContents(StrEq(firmwareImage.c_str()), Eq(session)))
+ .WillOnce(Return(true));
+
+ updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
+}