test: cleanup: firmware::commit() tests

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I4e083430c3eaa67d75c8add4cb97927faeb808da
diff --git a/test/firmware_commit_unittest.cpp b/test/firmware_commit_unittest.cpp
index 2766fd3..b3d023f 100644
--- a/test/firmware_commit_unittest.cpp
+++ b/test/firmware_commit_unittest.cpp
@@ -4,6 +4,7 @@
 #include "util.hpp"
 #include "verification_mock.hpp"
 
+#include <memory>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -17,20 +18,31 @@
 using ::testing::StrEq;
 using ::testing::StrictMock;
 
-TEST(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
+class FirmwareHandlerCommitTest : public ::testing::Test
+{
+  protected:
+    ImageHandlerMock imageMock1, imageMock2;
+    std::vector<HandlerPack> blobs;
+    std::vector<DataHandlerPack> data;
+
+    void SetUp() override
+    {
+        blobs = {
+            {hashBlobId, &imageMock1},
+            {"asdf", &imageMock2},
+        };
+
+        data = {
+            {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
+        };
+    }
+};
+
+TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage)
 {
     /* Verify the flash image returns failure on this command.  It's a fairly
      * artificial test.
      */
-    ImageHandlerMock imageMock1, imageMock2;
-    std::vector<HandlerPack> blobs = {
-        {hashBlobId, &imageMock1},
-        {"asdf", &imageMock2},
-    };
-
-    std::vector<DataHandlerPack> data = {
-        {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
-    };
 
     /* Verify it doesn't get called by using StrictMock. */
     std::unique_ptr<VerificationInterface> verifyMock =
@@ -47,20 +59,11 @@
     EXPECT_FALSE(handler->commit(0, {}));
 }
 
-TEST(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
+TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile)
 {
     /* Verify the hash file returns failure on this command.  It's a fairly
      * artificial test.
      */
-    ImageHandlerMock imageMock1, imageMock2;
-    std::vector<HandlerPack> blobs = {
-        {hashBlobId, &imageMock1},
-        {"asdf", &imageMock2},
-    };
-
-    std::vector<DataHandlerPack> data = {
-        {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
-    };
 
     /* Verify it doesn't get called by using StrictMock. */
     std::unique_ptr<VerificationInterface> verifyMock =
@@ -78,21 +81,11 @@
     EXPECT_FALSE(handler->commit(0, {}));
 }
 
-TEST(FirmwareHandlerCommitTest, VerifyCommitAcceptedOnVerifyBlob)
+TEST_F(FirmwareHandlerCommitTest, VerifyCommitAcceptedOnVerifyBlob)
 {
     /* Verify the verify blob lets you call this command, and it returns
      * success.
      */
-    ImageHandlerMock imageMock1, imageMock2;
-    std::vector<HandlerPack> blobs = {
-        {hashBlobId, &imageMock1},
-        {"asdf", &imageMock2},
-    };
-
-    std::vector<DataHandlerPack> data = {
-        {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
-    };
-
     auto verifyMock = CreateVerifyMock();
     auto verifyMockPtr = reinterpret_cast<VerificationMock*>(verifyMock.get());
 
@@ -107,21 +100,11 @@
     EXPECT_TRUE(handler->commit(0, {}));
 }
 
-TEST(FirmwareHandlerCommitTest, VerifyCommitCanOnlyBeCalledOnceForEffect)
+TEST_F(FirmwareHandlerCommitTest, VerifyCommitCanOnlyBeCalledOnceForEffect)
 {
     /* Verify you cannot call the commit() command once verification is
      * started, after which it will just return true.
      */
-    ImageHandlerMock imageMock1, imageMock2;
-    std::vector<HandlerPack> blobs = {
-        {hashBlobId, &imageMock1},
-        {"asdf", &imageMock2},
-    };
-
-    std::vector<DataHandlerPack> data = {
-        {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
-    };
-
     auto verifyMock = CreateVerifyMock();
     auto verifyMockPtr = reinterpret_cast<VerificationMock*>(verifyMock.get());