summaryrefslogtreecommitdiff
path: root/redfish-core/lib/ut
diff options
context:
space:
mode:
authorJohn Edward Broadbent <jebr@google.com>2021-06-28 21:32:33 +0300
committerEd Tanous <edtanous@google.com>2022-03-01 02:46:31 +0300
commitad5d7e7130db7c99d6d4d3c3a465b28c33f9be21 (patch)
tree84f53730b2b26f293c99127abf410eef832ecf62 /redfish-core/lib/ut
parent72374eb7fe42257e866dd088bc13520b0b28cffa (diff)
downloadbmcweb-ad5d7e7130db7c99d6d4d3c3a465b28c33f9be21.tar.xz
Adds new redfish unit testing for serviceroot
This type of testing can validate bmcwebs generated redfish. The ability to validate the output of bmcweb is extremely useful because it will guarantee correctness in certain cases. This is an example of redfish unit testing. The long term goal is to apply this type of testing to several other redfish responses. To make this change many previous changes were needed * Break serviceroot callback into the free function. * Change ownership of the request and response objects. * Change setCompleteRequestHandler logic Signed-off-by: John Edward Broadbent <jebr@google.com> Change-Id: I324daef0d80eb86f0f7383663727d64776f45279
Diffstat (limited to 'redfish-core/lib/ut')
-rw-r--r--redfish-core/lib/ut/service_root_test.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/redfish-core/lib/ut/service_root_test.cpp b/redfish-core/lib/ut/service_root_test.cpp
new file mode 100644
index 0000000000..a8358793d3
--- /dev/null
+++ b/redfish-core/lib/ut/service_root_test.cpp
@@ -0,0 +1,78 @@
+#include "http_request.hpp"
+#include "include/async_resp.hpp"
+#include "nlohmann/json.hpp"
+#include "redfish-core/lib/service_root.hpp"
+
+#include <memory>
+#include <string>
+
+#include "gmock/gmock.h"
+
+void assertServiceRootGet(crow::Response& res)
+{
+ nlohmann::json& json = res.jsonValue;
+ EXPECT_EQ(json["@odata.id"], "/redfish/v1");
+ EXPECT_EQ(json["@odata.type"], "#ServiceRoot.v1_11_0.ServiceRoot");
+
+ EXPECT_EQ(json["AccountService"]["@odata.id"],
+ "/redfish/v1/AccountService");
+ EXPECT_EQ(json["AccountService"].size(), 1);
+
+ EXPECT_EQ(json["CertificateService"]["@odata.id"],
+ "/redfish/v1/CertificateService");
+ EXPECT_EQ(json["CertificateService"].size(), 1);
+
+ EXPECT_EQ(json["Chassis"]["@odata.id"], "/redfish/v1/Chassis");
+ EXPECT_EQ(json["Chassis"].size(), 1);
+
+ EXPECT_EQ(json["EventService"]["@odata.id"], "/redfish/v1/EventService");
+ EXPECT_EQ(json["EventService"].size(), 1);
+
+ EXPECT_EQ(json["Id"], "RootService");
+ EXPECT_EQ(json["Links"]["Sessions"]["@odata.id"],
+ "/redfish/v1/SessionService/Sessions");
+ EXPECT_EQ(json["Links"].size(), 1);
+ EXPECT_EQ(json["Links"]["Sessions"].size(), 1);
+
+ EXPECT_EQ(json["Managers"]["@odata.id"], "/redfish/v1/Managers");
+ EXPECT_EQ(json["Managers"].size(), 1);
+
+ EXPECT_EQ(json["Name"], "Root Service");
+ EXPECT_EQ(json["RedfishVersion"], "1.9.0");
+
+ EXPECT_EQ(json["Registries"]["@odata.id"], "/redfish/v1/Registries");
+ EXPECT_EQ(json["Registries"].size(), 1);
+
+ EXPECT_EQ(json["SessionService"]["@odata.id"],
+ "/redfish/v1/SessionService");
+ EXPECT_EQ(json["SessionService"].size(), 1);
+
+ EXPECT_EQ(json["Systems"]["@odata.id"], "/redfish/v1/Systems");
+ EXPECT_EQ(json["Systems"].size(), 1);
+
+ EXPECT_EQ(json["Tasks"]["@odata.id"], "/redfish/v1/TaskService");
+ EXPECT_EQ(json["Tasks"].size(), 1);
+
+ EXPECT_EQ(json["TelemetryService"]["@odata.id"],
+ "/redfish/v1/TelemetryService");
+ EXPECT_EQ(json["TelemetryService"].size(), 1);
+
+ EXPECT_THAT(
+ json["UUID"],
+ testing::MatchesRegex("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-"
+ "9a-fA-F]{4}-[0-9a-fA-F]{12}"));
+
+ EXPECT_EQ(json["UpdateService"]["@odata.id"], "/redfish/v1/UpdateService");
+ EXPECT_EQ(20, json.size());
+}
+
+TEST(ServiceRootTest, ServiceRootConstructor)
+{
+ std::error_code ec;
+ crow::Request req({}, ec);
+ auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
+
+ shareAsyncResp->res.setCompleteRequestHandler(assertServiceRootGet);
+
+ redfish::handleServiceRootGet(req, shareAsyncResp);
+}