chassis: replace lambda with inline functions
It has been a convention that request route functions take inline
functions instead of lambdas. The benifets include less indents,
beging more readable + unit test-able (take a look at the unit test that
this commit adds for example).
This commit also fixed neccessary headers to make the test compile. The
headers of the unit test source is a complete list. But headers of the
core codes are not complete. These header clean up will be done in a
separate effort once https://gerrit.openbmc.org/c/openbmc/bmcweb/+/55138
is submitted.
Tested:
1. no service validator errors on real hardware.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I4b23ba54707cea947b5db771c72aa64899041511
diff --git a/redfish-core/lib/chassis_test.cpp b/redfish-core/lib/chassis_test.cpp
new file mode 100644
index 0000000..a043859
--- /dev/null
+++ b/redfish-core/lib/chassis_test.cpp
@@ -0,0 +1,60 @@
+#include "app.hpp"
+#include "async_resp.hpp"
+#include "chassis.hpp"
+#include "http_request.hpp"
+#include "http_response.hpp"
+
+#include <boost/beast/core/string_type.hpp>
+#include <boost/beast/http/message.hpp>
+#include <nlohmann/json.hpp>
+
+#include <system_error>
+
+#include <gtest/gtest.h>
+
+namespace redfish
+{
+namespace
+{
+
+void assertChassisResetActionInfoGet(const std::string& chassisId,
+ crow::Response& res)
+{
+ EXPECT_EQ(res.jsonValue["@odata.type"], "#ActionInfo.v1_1_2.ActionInfo");
+ EXPECT_EQ(res.jsonValue["@odata.id"],
+ "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo");
+ EXPECT_EQ(res.jsonValue["Name"], "Reset Action Info");
+
+ EXPECT_EQ(res.jsonValue["Id"], "ResetActionInfo");
+
+ nlohmann::json::array_t parameters;
+ nlohmann::json::object_t parameter;
+ parameter["Name"] = "ResetType";
+ parameter["Required"] = true;
+ parameter["DataType"] = "String";
+ nlohmann::json::array_t allowed;
+ allowed.push_back("PowerCycle");
+ parameter["AllowableValues"] = std::move(allowed);
+ parameters.push_back(std::move(parameter));
+
+ EXPECT_EQ(res.jsonValue["Parameters"], parameters);
+}
+
+TEST(HandleChassisResetActionInfoGet, StaticAttributesAreExpected)
+{
+
+ auto response = std::make_shared<bmcweb::AsyncResp>();
+ std::error_code err;
+ crow::Request request{{boost::beast::http::verb::get, "/whatever", 11},
+ err};
+
+ std::string fakeChassis = "fakeChassis";
+ response->res.setCompleteRequestHandler(
+ std::bind_front(assertChassisResetActionInfoGet, fakeChassis));
+
+ crow::App app;
+ handleChassisResetActionInfoGet(app, request, response, fakeChassis);
+}
+
+} // namespace
+} // namespace redfish
\ No newline at end of file