version-handler: add version-handler, blob handler
Implement version-handler: a blob handler for retrieving version
information about a blob.
Problem: ipmi-flash(firmware-handler) provides a mechanism to transfer
firmware updates, verify them and perform updates but there is no
mechanism to interrogate the firmware for its version.
Solution: version-handler provides handlers for retrieving information
about firmware blobs. Adding "version" syntax to "/flash/blob" entries
in the json configuration file enables this feature.
The mechanism to retrieve version is identical to the mechanism used by
firmware-handler to perform preparation, verification and updates (kick
off systemd targets).
Signed-off-by: Jason Ling <jasonling@google.com>
Change-Id: I28868ca8dd76d63af668d2e46b9359401d45f0bc
diff --git a/bmc/version-handler/test/version_createhandler_unittest.cpp b/bmc/version-handler/test/version_createhandler_unittest.cpp
new file mode 100644
index 0000000..8454ed0
--- /dev/null
+++ b/bmc/version-handler/test/version_createhandler_unittest.cpp
@@ -0,0 +1,70 @@
+#include "flags.hpp"
+#include "image_mock.hpp"
+#include "triggerable_mock.hpp"
+#include "util.hpp"
+#include "version_handler.hpp"
+
+#include <array>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace ipmi_flash
+{
+
+TEST(VersionHandlerCanHandleTest, VerifyGoodInfoMapPasses)
+{
+ VersionInfoMap test;
+ std::array blobNames{"blob0", "blob1", "blob2", "blob3"};
+ for (const auto& blobName : blobNames)
+ {
+ test.try_emplace(blobName,
+ VersionInfoPack(blobName,
+ std::make_unique<VersionActionPack>(
+ CreateTriggerMock()),
+ CreateImageMock()));
+ }
+ auto handler = VersionBlobHandler::create(std::move(test));
+ EXPECT_NE(handler, nullptr);
+}
+
+TEST(VersionCreateHandlerTest, VerifyEmptyInfoMapFails)
+{
+ VersionInfoMap test;
+ auto handler = VersionBlobHandler::create(std::move(test));
+ EXPECT_EQ(handler, nullptr);
+}
+
+TEST(VersionHandlerCanHandleTest, VerifyInfoMapWithNullActionPackFails)
+{
+ VersionInfoMap test;
+ test.try_emplace("blob0",
+ VersionInfoPack("blob0", nullptr, CreateImageMock()));
+ auto handler = VersionBlobHandler::create(std::move(test));
+ EXPECT_EQ(handler, nullptr);
+}
+
+TEST(VersionHandlerCanHandleTest, VerifyInfoMapWithNullTriggerableActionFails)
+{
+ VersionInfoMap test;
+ test.try_emplace(
+ "blob0",
+ VersionInfoPack("blob0", std::make_unique<VersionActionPack>(nullptr),
+ CreateImageMock()));
+ auto handler = VersionBlobHandler::create(std::move(test));
+ EXPECT_EQ(handler, nullptr);
+}
+
+TEST(VersionHandlerCanHandleTest, VerifyInfoMapWithNullImageHandlerFails)
+{
+ VersionInfoMap test;
+ test.try_emplace(
+ "blob0",
+ VersionInfoPack(
+ "blob0", std::make_unique<VersionActionPack>(CreateTriggerMock()),
+ nullptr));
+ auto handler = VersionBlobHandler::create(std::move(test));
+ EXPECT_EQ(handler, nullptr);
+}
+} // namespace ipmi_flash