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