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