1 #include "app.hpp"
2 #include "async_resp.hpp"
3 #include "http_request.hpp"
4 
5 #include <memory>
6 
7 #include <gmock/gmock.h> // IWYU pragma: keep
8 #include <gtest/gtest.h> // IWYU pragma: keep
9 
10 // IWYU pragma: no_include <gtest/gtest-message.h>
11 // IWYU pragma: no_include <gtest/gtest-test-part.h>
12 // IWYU pragma: no_include "gtest/gtest_pred_impl.h"
13 // IWYU pragma: no_include <gmock/gmock-matchers.h>
14 // IWYU pragma: no_include <gmock/gmock-more-matchers.h>
15 // IWYU pragma: no_include <gtest/gtest-matchers.h>
16 
17 namespace crow
18 {
19 namespace
20 {
21 
22 using ::bmcweb::AsyncResp;
23 using ::testing::Eq;
24 using ::testing::IsEmpty;
25 using ::testing::Pointee;
26 using ::testing::UnorderedElementsAre;
27 
28 TEST(GetRoutes, TestEmptyRoutes)
29 {
30     App app;
31     app.validate();
32 
33     EXPECT_THAT(app.getRoutes(), IsEmpty());
34 }
35 
36 // Tests that static urls are correctly passed
37 TEST(GetRoutes, TestOneRoute)
38 {
39     App app;
40 
41     BMCWEB_ROUTE(app, "/")
42     ([](const crow::Request& /*req*/,
43         const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});
44 
45     // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
46     // it is fixed
47     // EXPECT_THAT(app.getRoutes(),
48     // testing::ElementsAre(Pointee(Eq("/"))));
49 }
50 
51 // Tests that static urls are correctly passed
52 TEST(GetRoutes, TestlotsOfRoutes)
53 {
54     App app;
55     BMCWEB_ROUTE(app, "/")
56     ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
57     BMCWEB_ROUTE(app, "/foo")
58     ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
59     BMCWEB_ROUTE(app, "/bar")
60     ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
61     BMCWEB_ROUTE(app, "/baz")
62     ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
63     BMCWEB_ROUTE(app, "/boo")
64     ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
65     BMCWEB_ROUTE(app, "/moo")
66     ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
67 
68     app.validate();
69 
70     // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
71     // it is fixed
72     EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
73                                      // Pointee(Eq("/")),
74                                      Pointee(Eq("/foo")), Pointee(Eq("/bar")),
75                                      Pointee(Eq("/baz")), Pointee(Eq("/boo")),
76                                      Pointee(Eq("/moo"))));
77 }
78 } // namespace
79 } // namespace crow
80