Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 1 | #include "app.hpp" |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 2 | #include "routing.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 3 | |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 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> |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 17 | |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 18 | namespace crow |
| 19 | { |
| 20 | namespace |
| 21 | { |
| 22 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 23 | using ::bmcweb::AsyncResp; |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 24 | using ::testing::Eq; |
| 25 | using ::testing::IsEmpty; |
| 26 | using ::testing::Pointee; |
| 27 | using ::testing::UnorderedElementsAre; |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 28 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | TEST(GetRoutes, TestEmptyRoutes) |
| 30 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 31 | App app; |
| 32 | app.validate(); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 33 | |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 34 | EXPECT_THAT(app.getRoutes(), IsEmpty()); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // Tests that static urls are correctly passed |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 38 | TEST(GetRoutes, TestOneRoute) |
| 39 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 40 | App app; |
| 41 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 42 | BMCWEB_ROUTE(app, "/") |
| 43 | ([](const crow::Request& /*req*/, |
| 44 | const std::shared_ptr<AsyncResp>& /*asyncResp*/) {}); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 45 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 46 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 47 | // it is fixed |
| 48 | // EXPECT_THAT(app.getRoutes(), |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 49 | // testing::ElementsAre(Pointee(Eq("/")))); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // Tests that static urls are correctly passed |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | TEST(GetRoutes, TestlotsOfRoutes) |
| 54 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 55 | App app; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 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*/) {}); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 68 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 69 | app.validate(); |
| 70 | |
| 71 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 72 | // it is fixed |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 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")))); |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 78 | } |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 79 | } // namespace |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 80 | } // namespace crow |