make building handlers from json more generic
Problem: version-handler, a new feature that will be added to this
repository will also parse json files from the same directory ipmi-flash
does. Currently buildjson is a mix of some code that can be reused and
other code that is pretty specific to firmware updates; this makes it
hard to reuse the code.
Solution: factor out the generic parts and place it in bmc and then
leave the specific parts in firmware-handler. Also code changes have
been made to buildjson: wrap functions in a templated class that leaves
feature specific parsing as a pure virtual method.
Tested:
Ran the unit tests, which do test the parsing functionality.
Signed-off-by: Jason Ling <jasonling@google.com>
Change-Id: I021dc829a82d1719b4cb862cdfb224eca629a44d
diff --git a/bmc/firmware-handler/test/firmware_json_unittest.cpp b/bmc/firmware-handler/test/firmware_json_unittest.cpp
index 8f3ea30..235b33c 100644
--- a/bmc/firmware-handler/test/firmware_json_unittest.cpp
+++ b/bmc/firmware-handler/test/firmware_json_unittest.cpp
@@ -1,4 +1,4 @@
-#include "buildjson.hpp"
+#include "firmware_handlers_builder.hpp"
#include "general_systemd.hpp"
#include "skip_action.hpp"
@@ -40,8 +40,7 @@
}
}]
)"_json;
-
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, InvalidPreparationType)
@@ -70,7 +69,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, InvalidVerificationType)
@@ -99,7 +98,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, InvalidUpdateType)
@@ -128,7 +127,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, MissingHandler)
@@ -153,7 +152,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, MissingActions)
@@ -168,7 +167,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, MissingActionPreparation)
@@ -193,7 +192,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, MissingActionVerification)
@@ -217,7 +216,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, MissingActionUpdate)
@@ -243,7 +242,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, TwoConfigsOneInvalidReturnsValid)
@@ -289,7 +288,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h[0].blobId, "/flash/image2");
EXPECT_EQ(h.size(), 1);
}
@@ -329,7 +328,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, VerifyMinimumBlobNameLength)
@@ -360,7 +359,7 @@
}]
)"_json;
- EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+ EXPECT_THAT(FirmwareHandlersBuilder().buildHandlerFromJson(j2), IsEmpty());
}
TEST(FirmwareJsonTest, VerifySystemdWithReboot)
@@ -389,7 +388,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h[0].blobId, "/flash/image");
EXPECT_FALSE(h[0].handler == nullptr);
EXPECT_FALSE(h[0].actions == nullptr);
@@ -447,7 +446,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h.size(), 2);
EXPECT_EQ(h[0].blobId, "/flash/image");
EXPECT_EQ(h[1].blobId, "/flash/bios");
@@ -480,7 +479,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h[0].blobId, "/flash/image");
EXPECT_FALSE(h[0].handler == nullptr);
EXPECT_FALSE(h[0].actions == nullptr);
@@ -523,7 +522,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h[0].blobId, "/flash/image");
EXPECT_FALSE(h[0].handler == nullptr);
EXPECT_FALSE(h[0].actions == nullptr);
@@ -567,7 +566,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h[0].blobId, "/flash/image");
EXPECT_FALSE(h[0].handler == nullptr);
EXPECT_FALSE(h[0].actions == nullptr);
@@ -607,7 +606,7 @@
}]
)"_json;
- auto h = buildHandlerFromJson(j2);
+ auto h = FirmwareHandlersBuilder().buildHandlerFromJson(j2);
EXPECT_EQ(h[0].blobId, "/flash/image");
EXPECT_FALSE(h[0].handler == nullptr);
EXPECT_FALSE(h[0].actions == nullptr);