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 | |
| 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 | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 41 | BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 42 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 43 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 44 | // it is fixed |
| 45 | // EXPECT_THAT(app.getRoutes(), |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 46 | // testing::ElementsAre(Pointee(Eq("/")))); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // Tests that static urls are correctly passed |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 50 | TEST(GetRoutes, TestlotsOfRoutes) |
| 51 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 52 | App app; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); |
| 54 | BMCWEB_ROUTE(app, "/foo")([]() { return boost::beast::http::status::ok; }); |
| 55 | BMCWEB_ROUTE(app, "/bar")([]() { return boost::beast::http::status::ok; }); |
| 56 | BMCWEB_ROUTE(app, "/baz")([]() { return boost::beast::http::status::ok; }); |
| 57 | BMCWEB_ROUTE(app, "/boo")([]() { return boost::beast::http::status::ok; }); |
| 58 | BMCWEB_ROUTE(app, "/moo")([]() { return boost::beast::http::status::ok; }); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 59 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 60 | app.validate(); |
| 61 | |
| 62 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 63 | // it is fixed |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 64 | EXPECT_THAT(app.getRoutes(), UnorderedElementsAre( |
| 65 | // Pointee(Eq("/")), |
| 66 | Pointee(Eq("/foo")), Pointee(Eq("/bar")), |
| 67 | Pointee(Eq("/baz")), Pointee(Eq("/boo")), |
| 68 | Pointee(Eq("/moo")))); |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 69 | } |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 70 | } // namespace |
| 71 | } // namespace crow |