test: firmware verificationCompleted: stat(blob)

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I1c2247e0b09e3faa846871d108901deb97f81bf3
diff --git a/test/firmware_state_verificationcompleted_unittest.cpp b/test/firmware_state_verificationcompleted_unittest.cpp
index 9f87573..f06193e 100644
--- a/test/firmware_state_verificationcompleted_unittest.cpp
+++ b/test/firmware_state_verificationcompleted_unittest.cpp
@@ -44,8 +44,11 @@
     : public IpmiOnlyFirmwareStaticTest
 {
   protected:
-    void getToVerificationCompleted()
+    void getToVerificationCompleted(VerifyCheckResponses checkResponse)
     {
+        /* The hash was not sent up, as it's technically optional.  Therefore,
+         * there is no active hash file.
+         */
         auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
         EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
         EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
@@ -65,7 +68,7 @@
                   realHandler->getCurrentState());
 
         EXPECT_CALL(*verifyMockPtr, checkVerificationState())
-            .WillOnce(Return(VerifyCheckResponses::success));
+            .WillOnce(Return(checkResponse));
         blobs::BlobMeta meta;
         EXPECT_TRUE(handler->stat(session, &meta));
         EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
@@ -77,7 +80,7 @@
         blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
 };
 
-/*
+/* TODO:
  * canHandleBlob(blob)
  * getBlobIds
  * deleteBlob(blob)
@@ -87,6 +90,44 @@
 /*
  * stat(blob)
  */
+TEST_F(FirmwareHandlerVerificationCompletedTest,
+       StatOnActiveImageReturnsFailure)
+{
+    getToVerificationCompleted(VerifyCheckResponses::success);
+    ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId));
+
+    blobs::BlobMeta meta;
+    EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
+}
+
+TEST_F(FirmwareHandlerVerificationCompletedTest, StatOnVerifyBlobReturnsFailure)
+{
+    getToVerificationCompleted(VerifyCheckResponses::success);
+    ASSERT_TRUE(handler->canHandleBlob(verifyBlobId));
+
+    blobs::BlobMeta meta;
+    EXPECT_FALSE(handler->stat(verifyBlobId, &meta));
+}
+
+TEST_F(FirmwareHandlerVerificationCompletedTest,
+       StatOnNormalBlobsReturnsSuccess)
+{
+    getToVerificationCompleted(VerifyCheckResponses::success);
+
+    blobs::BlobMeta expected;
+    expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
+    expected.size = 0;
+
+    std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
+    for (const auto& blob : testBlobs)
+    {
+        ASSERT_TRUE(handler->canHandleBlob(blob));
+
+        blobs::BlobMeta meta = {};
+        EXPECT_TRUE(handler->stat(blob, &meta));
+        EXPECT_EQ(expected, meta);
+    }
+}
 
 /*
  * stat(session) - the verify blobid is open in this state, so stat on that once