test: firmware verificationPending: canHandleBlob

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I482c4c8dfb80d9453fb9d61c65d58df88d244312
diff --git a/test/Makefile.am b/test/Makefile.am
index abac332..b98cf53 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -34,7 +34,8 @@
 	firmware_commit_unittest \
 	file_handler_unittest \
 	firmware_state_notyetstarted_unittest \
-	firmware_state_uploadinprogress_unittest
+	firmware_state_uploadinprogress_unittest \
+	firmware_state_verificationpending_unittest
 
 if BUILD_HOST_TOOL
 check_PROGRAMS += \
@@ -87,6 +88,9 @@
 firmware_state_uploadinprogress_unittest_SOURCES = firmware_state_uploadinprogress_unittest.cpp
 firmware_state_uploadinprogress_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
 
+firmware_state_verificationpending_unittest_SOURCES = firmware_state_verificationpending_unittest.cpp
+firmware_state_verificationpending_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
+
 if BUILD_HOST_TOOL
 tools_bt_unittest_SOURCES = tools_bt_unittest.cpp
 tools_bt_unittest_LDADD = $(top_builddir)/tools/libupdater.la
diff --git a/test/firmware_state_verificationpending_unittest.cpp b/test/firmware_state_verificationpending_unittest.cpp
new file mode 100644
index 0000000..e376232
--- /dev/null
+++ b/test/firmware_state_verificationpending_unittest.cpp
@@ -0,0 +1,87 @@
+/**
+ * The goal of these tests is to verify the behavior of all blob commands given
+ * the current state is verificationPending.  This state is achieved as a
+ * transition out of uploadInProgress.
+ */
+#include "firmware_handler.hpp"
+#include "firmware_unittest.hpp"
+#include "util.hpp"
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace ipmi_flash
+{
+namespace
+{
+
+using ::testing::Return;
+
+/*
+ * There are the following calls (parameters may vary):
+ * canHandleBlob(blob)
+ * getBlobIds
+ * deleteBlob(blob)
+ * stat(blob)
+ * stat(session)
+ * open(blob)
+ * close(session)
+ * writemeta(session)
+ * write(session)
+ * read(session)
+ * commit(session)
+ *
+ * Testing canHandleBlob is uninteresting in this state.  Getting the BlobIDs
+ * will inform what canHandleBlob will return.
+ */
+
+class FirmwareHandlerVerificationPendingTest : public IpmiOnlyFirmwareStaticTest
+{
+  protected:
+    void getToVerificationPending(const std::string& blobId)
+    {
+        auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
+        EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
+        EXPECT_TRUE(handler->open(session, flags, blobId));
+        EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
+                  realHandler->getCurrentState());
+        EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
+        handler->close(session);
+        EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
+                  realHandler->getCurrentState());
+    }
+
+    std::uint16_t session = 1;
+    std::uint16_t flags =
+        blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
+};
+
+/*
+ * getBlobIds
+ * deleteBlob(blob)
+ * stat(blob)
+ * stat(session)
+ * open(blob)
+ * close(session)
+ * writemeta(session)
+ * write(session)
+ * read(session)
+ * commit(session)
+ */
+
+TEST_F(FirmwareHandlerVerificationPendingTest, VerifyBlobIdAvailableInState)
+{
+    /* Only in the verificationPending state (and later), should the
+     * verifyBlobId be present. */
+
+    /* TODO: Add this test in when the change is made. */
+    // EXPECT_FALSE(handler->canHandleBlob(verifyBlobId));
+    getToVerificationPending(staticLayoutBlobId);
+    EXPECT_TRUE(handler->canHandleBlob(verifyBlobId));
+}
+
+} // namespace
+} // namespace ipmi_flash