version-handler: Refactor handler construction
Instead of requiring callers to build maps and info blobs, take the
minimal required amount of information about the blob configuration and
build required datastructures internally.
This reduces the amount of code, and nearly eliminates all of the
untested code in main.cpp.
Change-Id: Iaa398eb404814e9263e6707b71b38a9831d96697
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/bmc/version-handler/test/version_createhandler_unittest.cpp b/bmc/version-handler/test/version_createhandler_unittest.cpp
index c748f7f..849d1a4 100644
--- a/bmc/version-handler/test/version_createhandler_unittest.cpp
+++ b/bmc/version-handler/test/version_createhandler_unittest.cpp
@@ -1,12 +1,8 @@
-#include "flags.hpp"
-#include "image_mock.hpp"
-#include "triggerable_mock.hpp"
-#include "util.hpp"
#include "version_handler.hpp"
+#include "version_mock.hpp"
#include <array>
-#include <string>
-#include <vector>
+#include <utility>
#include <gtest/gtest.h>
@@ -15,18 +11,20 @@
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);
+ constexpr std::array blobs{"blob0", "blob1"};
+ VersionBlobHandler handler(createMockVersionConfigs(blobs));
+ EXPECT_THAT(handler.getBlobIds(),
+ testing::UnorderedElementsAreArray(blobs));
+}
+
+TEST(VersionHandlerCanHandleTest, VerifyDuplicatesIgnored)
+{
+ constexpr std::array blobs{"blob0"};
+ auto configs = createMockVersionConfigs(blobs);
+ configs.push_back(createMockVersionConfig(blobs[0]));
+ VersionBlobHandler handler(std::move(configs));
+ EXPECT_THAT(handler.getBlobIds(),
+ testing::UnorderedElementsAreArray(blobs));
}
} // namespace ipmi_flash