regulators: Add inventory path to Chassis class
A previous commit added the "inventory_path" property to the "chassis"
object in the JSON configuration file.
This commit adds that new property to the C++ implementation:
* Chassis class and associated gtests
* JSON configuration file parser functions and associated gtests
* Other gtests affected by the change to the Chassis constructor
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I7406f874263d01e6faa2b8c333cb1baf915cf2ac
diff --git a/phosphor-regulators/test/config_file_parser_tests.cpp b/phosphor-regulators/test/config_file_parser_tests.cpp
index 19bf73b..c2cf08e 100644
--- a/phosphor-regulators/test/config_file_parser_tests.cpp
+++ b/phosphor-regulators/test/config_file_parser_tests.cpp
@@ -760,6 +760,8 @@
)"_json;
std::unique_ptr<Chassis> chassis = parseChassis(element);
EXPECT_EQ(chassis->getNumber(), 1);
+ EXPECT_EQ(chassis->getInventoryPath(),
+ "/xyz/openbmc_project/inventory/system/chassis");
EXPECT_EQ(chassis->getDevices().size(), 0);
}
@@ -769,6 +771,7 @@
{
"comments": [ "comments property" ],
"number": 2,
+ "inventory_path": "system/chassis2",
"devices": [
{
"id": "vdd_regulator",
@@ -785,6 +788,8 @@
)"_json;
std::unique_ptr<Chassis> chassis = parseChassis(element);
EXPECT_EQ(chassis->getNumber(), 2);
+ EXPECT_EQ(chassis->getInventoryPath(),
+ "/xyz/openbmc_project/inventory/system/chassis2");
EXPECT_EQ(chassis->getDevices().size(), 1);
EXPECT_EQ(chassis->getDevices()[0]->getID(), "vdd_regulator");
}
@@ -805,6 +810,40 @@
EXPECT_STREQ(e.what(), "Element is not an unsigned integer");
}
+ // Test where fails: inventory_path is invalid: Not a string
+ try
+ {
+ const json element = R"(
+ {
+ "number": 2,
+ "inventory_path": true
+ }
+ )"_json;
+ parseChassis(element);
+ ADD_FAILURE() << "Should not have reached this line.";
+ }
+ catch (const std::invalid_argument& e)
+ {
+ EXPECT_STREQ(e.what(), "Element is not a string");
+ }
+
+ // Test where fails: inventory_path is invalid: Empty string
+ try
+ {
+ const json element = R"(
+ {
+ "number": 2,
+ "inventory_path": ""
+ }
+ )"_json;
+ parseChassis(element);
+ ADD_FAILURE() << "Should not have reached this line.";
+ }
+ catch (const std::invalid_argument& e)
+ {
+ EXPECT_STREQ(e.what(), "Element contains an empty string");
+ }
+
// Test where fails: Invalid property specified
try
{