1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #include "async_resp.hpp"
4 #include "google/google_service_root.hpp"
5 #include "http_request.hpp"
6 #include "http_response.hpp"
7
8 #include <boost/beast/http/verb.hpp>
9 #include <nlohmann/json.hpp>
10
11 #include <memory>
12 #include <system_error>
13
14 #include <gtest/gtest.h>
15
16 namespace crow::google_api
17 {
18 namespace
19 {
20
validateServiceRootGet(crow::Response & res)21 void validateServiceRootGet(crow::Response& res)
22 {
23 nlohmann::json& json = res.jsonValue;
24 EXPECT_EQ(json["@odata.id"], "/google/v1");
25 EXPECT_EQ(json["@odata.type"],
26 "#GoogleServiceRoot.v1_0_0.GoogleServiceRoot");
27 EXPECT_EQ(json["@odata.id"], "/google/v1");
28 EXPECT_EQ(json["Id"], "Google Rest RootService");
29 EXPECT_EQ(json["Name"], "Google Service Root");
30 EXPECT_EQ(json["Version"], "1.0.0");
31 EXPECT_EQ(json["RootOfTrustCollection"]["@odata.id"],
32 "/google/v1/RootOfTrustCollection");
33 }
34
TEST(HandleGoogleV1Get,OnSuccess)35 TEST(HandleGoogleV1Get, OnSuccess)
36 {
37 std::error_code ec;
38 auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
39
40 asyncResp->res.setCompleteRequestHandler(validateServiceRootGet);
41
42 crow::Request dummyRequest{{boost::beast::http::verb::get, "", 11}, ec};
43 handleGoogleV1Get(dummyRequest, asyncResp);
44 }
45
46 } // namespace
47 } // namespace crow::google_api
48