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