Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame^] | 1 | #include "app.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2 | |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 3 | #include "gmock/gmock.h" |
| 4 | #include "gtest/gtest.h" |
| 5 | |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame^] | 6 | namespace crow |
| 7 | { |
| 8 | namespace |
| 9 | { |
| 10 | |
| 11 | using ::testing::Eq; |
| 12 | using ::testing::IsEmpty; |
| 13 | using ::testing::Pointee; |
| 14 | using ::testing::UnorderedElementsAre; |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 15 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 16 | TEST(GetRoutes, TestEmptyRoutes) |
| 17 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 18 | App app; |
| 19 | app.validate(); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 20 | |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame^] | 21 | EXPECT_THAT(app.getRoutes(), IsEmpty()); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | // Tests that static urls are correctly passed |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 25 | TEST(GetRoutes, TestOneRoute) |
| 26 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 27 | App app; |
| 28 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 30 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 31 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 32 | // it is fixed |
| 33 | // EXPECT_THAT(app.getRoutes(), |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame^] | 34 | // testing::ElementsAre(Pointee(Eq("/")))); |
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, TestlotsOfRoutes) |
| 39 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 40 | App app; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 41 | BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); |
| 42 | BMCWEB_ROUTE(app, "/foo")([]() { return boost::beast::http::status::ok; }); |
| 43 | BMCWEB_ROUTE(app, "/bar")([]() { return boost::beast::http::status::ok; }); |
| 44 | BMCWEB_ROUTE(app, "/baz")([]() { return boost::beast::http::status::ok; }); |
| 45 | BMCWEB_ROUTE(app, "/boo")([]() { return boost::beast::http::status::ok; }); |
| 46 | BMCWEB_ROUTE(app, "/moo")([]() { return boost::beast::http::status::ok; }); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 47 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 48 | app.validate(); |
| 49 | |
| 50 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 51 | // it is fixed |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame^] | 52 | EXPECT_THAT(app.getRoutes(), UnorderedElementsAre( |
| 53 | // Pointee(Eq("/")), |
| 54 | Pointee(Eq("/foo")), Pointee(Eq("/bar")), |
| 55 | Pointee(Eq("/baz")), Pointee(Eq("/boo")), |
| 56 | Pointee(Eq("/moo")))); |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 57 | } |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame^] | 58 | } // namespace |
| 59 | } // namespace crow |