blob: dc6e427e7aa5b94e045aa8f4ea29261ed93c73d3 [file] [log] [blame]
Nan Zhou4dd73a12022-06-13 22:38:52 +00001#include "app.hpp"
Ed Tanousf0b59af2024-03-20 13:38:04 -07002#include "async_resp.hpp"
3#include "http_request.hpp"
Nan Zhoud5c80ad2022-07-11 01:16:31 +00004
5#include <memory>
6
Ed Tanous478b7ad2024-07-15 19:11:54 -07007#include <gmock/gmock.h>
8#include <gtest/gtest.h>
Ed Tanousb4a7bfa2017-04-04 17:23:00 -07009
Nan Zhou4dd73a12022-06-13 22:38:52 +000010namespace crow
11{
12namespace
13{
14
Ed Tanous15a42df2023-02-09 18:08:23 -080015using ::bmcweb::AsyncResp;
Nan Zhou4dd73a12022-06-13 22:38:52 +000016using ::testing::Eq;
17using ::testing::IsEmpty;
18using ::testing::Pointee;
19using ::testing::UnorderedElementsAre;
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070020
Ed Tanous1abe55e2018-09-05 08:30:59 -070021TEST(GetRoutes, TestEmptyRoutes)
22{
Nan Zhou5ad77202022-06-13 22:33:55 +000023 App app;
24 app.validate();
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070025
Nan Zhou4dd73a12022-06-13 22:38:52 +000026 EXPECT_THAT(app.getRoutes(), IsEmpty());
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070027}
28
29// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070030TEST(GetRoutes, TestOneRoute)
31{
Nan Zhou5ad77202022-06-13 22:33:55 +000032 App app;
33
Ed Tanous15a42df2023-02-09 18:08:23 -080034 BMCWEB_ROUTE(app, "/")
35 ([](const crow::Request& /*req*/,
36 const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070037
Nan Zhou5ad77202022-06-13 22:33:55 +000038 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
39 // it is fixed
40 // EXPECT_THAT(app.getRoutes(),
Nan Zhou4dd73a12022-06-13 22:38:52 +000041 // testing::ElementsAre(Pointee(Eq("/"))));
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070042}
43
44// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070045TEST(GetRoutes, TestlotsOfRoutes)
46{
Nan Zhou5ad77202022-06-13 22:33:55 +000047 App app;
Ed Tanous15a42df2023-02-09 18:08:23 -080048 BMCWEB_ROUTE(app, "/")
49 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
50 BMCWEB_ROUTE(app, "/foo")
51 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
52 BMCWEB_ROUTE(app, "/bar")
53 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
54 BMCWEB_ROUTE(app, "/baz")
55 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
56 BMCWEB_ROUTE(app, "/boo")
57 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
58 BMCWEB_ROUTE(app, "/moo")
59 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070060
Nan Zhou5ad77202022-06-13 22:33:55 +000061 app.validate();
62
63 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
64 // it is fixed
Nan Zhou4dd73a12022-06-13 22:38:52 +000065 EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
66 // Pointee(Eq("/")),
67 Pointee(Eq("/foo")), Pointee(Eq("/bar")),
68 Pointee(Eq("/baz")), Pointee(Eq("/boo")),
69 Pointee(Eq("/moo"))));
Ed Tanous04e438c2020-10-03 08:06:26 -070070}
Nan Zhou4dd73a12022-06-13 22:38:52 +000071} // namespace
Ed Tanous44e45182022-07-26 16:47:23 -070072} // namespace crow