entity-manager: fixes for logDeviceAdded/Removed
Follow-up patch to fix issues found in comments of [1].
- Use explicit type rather than 'auto' for local variable
- Setup a return variable to avoid duplicate initial value "Unknown"
- Fix string value read to avoid uncaught exception
- Remove unused boost include
- Add unit tests
Tested: Unit tests pass.
References:
[1] https://gerrit.openbmc.org/c/openbmc/entity-manager/+/84340
Change-Id: I3d5540860e8ef8e590bc2685ce559c53dc8452b5
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/entity_manager/log_device_inventory.cpp b/test/entity_manager/log_device_inventory.cpp
new file mode 100644
index 0000000..cbf7bd4
--- /dev/null
+++ b/test/entity_manager/log_device_inventory.cpp
@@ -0,0 +1,49 @@
+
+#include "entity_manager/log_device_inventory.hpp"
+
+#include <gtest/gtest.h>
+
+TEST(LogDevicInventory, QueryInvInfoSuccess)
+{
+ nlohmann::json record = nlohmann::json::parse(R"(
+{
+ "Name": "Supermicro PWS 920P SQ 0",
+ "Type": "PowerSupply",
+ "xyz.openbmc_project.Inventory.Decorator.Asset": {
+ "Manufacturer": "Supermicro",
+ "Model": "PWS 920P SQ",
+ "PartNumber": "328923",
+ "SerialNumber": "43829239"
+ }
+}
+ )");
+
+ InvAddRemoveInfo info = queryInvInfo(record);
+
+ EXPECT_EQ(info.name, "Supermicro PWS 920P SQ 0");
+ EXPECT_EQ(info.type, "PowerSupply");
+ EXPECT_EQ(info.sn, "43829239");
+ EXPECT_EQ(info.model, "PWS 920P SQ");
+}
+
+TEST(LogDevicInventory, QueryInvInfoNoModelFound)
+{
+ nlohmann::json record = nlohmann::json::parse(R"(
+{
+ "Name": "Supermicro PWS 920P SQ 0",
+ "Type": "PowerSupply",
+ "xyz.openbmc_project.Inventory.Decorator.Asset": {
+ "Manufacturer": "Supermicro",
+ "PartNumber": "328923",
+ "SerialNumber": "43829239"
+ }
+}
+ )");
+
+ InvAddRemoveInfo info = queryInvInfo(record);
+
+ EXPECT_EQ(info.name, "Supermicro PWS 920P SQ 0");
+ EXPECT_EQ(info.type, "PowerSupply");
+ EXPECT_EQ(info.sn, "43829239");
+ EXPECT_EQ(info.model, "Unknown");
+}
diff --git a/test/entity_manager/meson.build b/test/entity_manager/meson.build
index d0ac54c..43d4689 100644
--- a/test/entity_manager/meson.build
+++ b/test/entity_manager/meson.build
@@ -16,3 +16,22 @@
include_directories: test_include_dir,
),
)
+
+test(
+ 'test_log_device_inventory',
+ executable(
+ 'test_log_device_inventory',
+ 'log_device_inventory.cpp',
+ cpp_args: test_boost_args,
+ dependencies: [
+ boost,
+ gtest,
+ nlohmann_json_dep,
+ phosphor_logging_dep,
+ sdbusplus,
+ valijson,
+ ],
+ link_with: entity_manager_lib,
+ include_directories: test_include_dir,
+ ),
+)