regulators: Implements support for run_rule

Implements support for parsing the run_rule JSON elements in the
configuration file parser.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I9b8d96716a7710e3829fc346d89ef418cc091858
diff --git a/phosphor-regulators/test/config_file_parser_tests.cpp b/phosphor-regulators/test/config_file_parser_tests.cpp
index df2d87e..9942c04 100644
--- a/phosphor-regulators/test/config_file_parser_tests.cpp
+++ b/phosphor-regulators/test/config_file_parser_tests.cpp
@@ -24,6 +24,7 @@
 #include "pmbus_utils.hpp"
 #include "pmbus_write_vout_command_action.hpp"
 #include "rule.hpp"
+#include "run_rule_action.hpp"
 #include "tmp_file.hpp"
 
 #include <sys/stat.h> // for chmod()
@@ -318,7 +319,15 @@
     }
 
     // Test where works: run_rule action type specified
-    // TODO: Not implemented yet
+    {
+        const json element = R"(
+            {
+              "run_rule": "set_voltage_rule"
+            }
+        )"_json;
+        std::unique_ptr<Action> action = parseAction(element);
+        EXPECT_NE(action.get(), nullptr);
+    }
 
     // Test where works: set_device action type specified
     // TODO: Not implemented yet
@@ -1673,6 +1682,40 @@
     }
 }
 
+TEST(ConfigFileParserTests, ParseRunRule)
+{
+    // Test where works
+    {
+        const json element = "vdd_regulator";
+        std::unique_ptr<RunRuleAction> action = parseRunRule(element);
+        EXPECT_EQ(action->getRuleID(), "vdd_regulator");
+    }
+
+    // Test where fails: Element is not a string
+    try
+    {
+        const json element = 1;
+        parseRunRule(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: Empty string
+    try
+    {
+        const json element = "";
+        parseRunRule(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(ConfigFileParserTests, ParseString)
 {
     // Test where works: Empty string