Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 3 | #include "app.hpp" |
Ed Tanous | f0b59af | 2024-03-20 13:38:04 -0700 | [diff] [blame] | 4 | #include "async_resp.hpp" |
| 5 | #include "http_request.hpp" |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 6 | |
| 7 | #include <memory> |
| 8 | |
Ed Tanous | 478b7ad | 2024-07-15 19:11:54 -0700 | [diff] [blame] | 9 | #include <gmock/gmock.h> |
| 10 | #include <gtest/gtest.h> |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 11 | |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 12 | namespace crow |
| 13 | { |
| 14 | namespace |
| 15 | { |
| 16 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 17 | using ::bmcweb::AsyncResp; |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 18 | using ::testing::Eq; |
| 19 | using ::testing::IsEmpty; |
| 20 | using ::testing::Pointee; |
| 21 | using ::testing::UnorderedElementsAre; |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 22 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 23 | TEST(GetRoutes, TestEmptyRoutes) |
| 24 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 25 | App app; |
| 26 | app.validate(); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 27 | |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 28 | EXPECT_THAT(app.getRoutes(), IsEmpty()); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // Tests that static urls are correctly passed |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 32 | TEST(GetRoutes, TestOneRoute) |
| 33 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 34 | App app; |
| 35 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 36 | BMCWEB_ROUTE(app, "/") |
| 37 | ([](const crow::Request& /*req*/, |
| 38 | const std::shared_ptr<AsyncResp>& /*asyncResp*/) {}); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 39 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 40 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 41 | // it is fixed |
| 42 | // EXPECT_THAT(app.getRoutes(), |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 43 | // testing::ElementsAre(Pointee(Eq("/")))); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | // Tests that static urls are correctly passed |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 47 | TEST(GetRoutes, TestlotsOfRoutes) |
| 48 | { |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 49 | App app; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 50 | BMCWEB_ROUTE(app, "/") |
| 51 | ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); |
| 52 | BMCWEB_ROUTE(app, "/foo") |
| 53 | ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); |
| 54 | BMCWEB_ROUTE(app, "/bar") |
| 55 | ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); |
| 56 | BMCWEB_ROUTE(app, "/baz") |
| 57 | ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); |
| 58 | BMCWEB_ROUTE(app, "/boo") |
| 59 | ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); |
| 60 | BMCWEB_ROUTE(app, "/moo") |
| 61 | ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 62 | |
Nan Zhou | 5ad7720 | 2022-06-13 22:33:55 +0000 | [diff] [blame] | 63 | app.validate(); |
| 64 | |
| 65 | // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once |
| 66 | // it is fixed |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 67 | EXPECT_THAT(app.getRoutes(), UnorderedElementsAre( |
| 68 | // Pointee(Eq("/")), |
| 69 | Pointee(Eq("/foo")), Pointee(Eq("/bar")), |
| 70 | Pointee(Eq("/baz")), Pointee(Eq("/boo")), |
| 71 | Pointee(Eq("/moo")))); |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 72 | } |
Nan Zhou | 4dd73a1 | 2022-06-13 22:38:52 +0000 | [diff] [blame] | 73 | } // namespace |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 74 | } // namespace crow |