1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3c33a039bSNan Zhou #include "app.hpp"
4f0b59af4SEd Tanous #include "async_resp.hpp"
5f0b59af4SEd Tanous #include "http_request.hpp"
6c33a039bSNan Zhou
7c33a039bSNan Zhou #include <memory>
8c33a039bSNan Zhou
9478b7adfSEd Tanous #include <gmock/gmock.h>
10478b7adfSEd Tanous #include <gtest/gtest.h>
11c33a039bSNan Zhou
12c33a039bSNan Zhou namespace crow
13c33a039bSNan Zhou {
14c33a039bSNan Zhou namespace
15c33a039bSNan Zhou {
16c33a039bSNan Zhou
1715a42df0SEd Tanous using ::bmcweb::AsyncResp;
18c33a039bSNan Zhou using ::testing::Eq;
19c33a039bSNan Zhou using ::testing::IsEmpty;
20c33a039bSNan Zhou using ::testing::Pointee;
21c33a039bSNan Zhou using ::testing::UnorderedElementsAre;
22c33a039bSNan Zhou
TEST(GetRoutes,TestEmptyRoutes)23c33a039bSNan Zhou TEST(GetRoutes, TestEmptyRoutes)
24c33a039bSNan Zhou {
25c33a039bSNan Zhou App app;
26c33a039bSNan Zhou app.validate();
27c33a039bSNan Zhou
28c33a039bSNan Zhou EXPECT_THAT(app.getRoutes(), IsEmpty());
29c33a039bSNan Zhou }
30c33a039bSNan Zhou
31c33a039bSNan Zhou // Tests that static urls are correctly passed
TEST(GetRoutes,TestOneRoute)32c33a039bSNan Zhou TEST(GetRoutes, TestOneRoute)
33c33a039bSNan Zhou {
34c33a039bSNan Zhou App app;
35c33a039bSNan Zhou
3615a42df0SEd Tanous BMCWEB_ROUTE(app, "/")
3715a42df0SEd Tanous ([](const crow::Request& /*req*/,
3815a42df0SEd Tanous const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});
39c33a039bSNan Zhou
40c33a039bSNan Zhou // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
41c33a039bSNan Zhou // it is fixed
42c33a039bSNan Zhou // EXPECT_THAT(app.getRoutes(),
43c33a039bSNan Zhou // testing::ElementsAre(Pointee(Eq("/"))));
44c33a039bSNan Zhou }
45c33a039bSNan Zhou
46c33a039bSNan Zhou // Tests that static urls are correctly passed
TEST(GetRoutes,TestlotsOfRoutes)47c33a039bSNan Zhou TEST(GetRoutes, TestlotsOfRoutes)
48c33a039bSNan Zhou {
49c33a039bSNan Zhou App app;
5015a42df0SEd Tanous BMCWEB_ROUTE(app, "/")
5115a42df0SEd Tanous ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
5215a42df0SEd Tanous BMCWEB_ROUTE(app, "/foo")
5315a42df0SEd Tanous ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
5415a42df0SEd Tanous BMCWEB_ROUTE(app, "/bar")
5515a42df0SEd Tanous ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
5615a42df0SEd Tanous BMCWEB_ROUTE(app, "/baz")
5715a42df0SEd Tanous ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
5815a42df0SEd Tanous BMCWEB_ROUTE(app, "/boo")
5915a42df0SEd Tanous ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
6015a42df0SEd Tanous BMCWEB_ROUTE(app, "/moo")
6115a42df0SEd Tanous ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
62c33a039bSNan Zhou
63c33a039bSNan Zhou app.validate();
64c33a039bSNan Zhou
65c33a039bSNan Zhou // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
66c33a039bSNan Zhou // it is fixed
67c33a039bSNan Zhou EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
68c33a039bSNan Zhou // Pointee(Eq("/")),
69c33a039bSNan Zhou Pointee(Eq("/foo")), Pointee(Eq("/bar")),
70c33a039bSNan Zhou Pointee(Eq("/baz")), Pointee(Eq("/boo")),
71c33a039bSNan Zhou Pointee(Eq("/moo"))));
72c33a039bSNan Zhou }
73c33a039bSNan Zhou } // namespace
74c33a039bSNan Zhou } // namespace crow
75