blob: 0c3f8de6083311f937c61ffa0ed8cfe01d177836 [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
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 Tanousb4a7bfa2017-04-04 17:23:00 -070016
Nan Zhou4dd73a12022-06-13 22:38:52 +000017namespace crow
18{
19namespace
20{
21
Ed Tanous15a42df2023-02-09 18:08:23 -080022using ::bmcweb::AsyncResp;
Nan Zhou4dd73a12022-06-13 22:38:52 +000023using ::testing::Eq;
24using ::testing::IsEmpty;
25using ::testing::Pointee;
26using ::testing::UnorderedElementsAre;
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070027
Ed Tanous1abe55e2018-09-05 08:30:59 -070028TEST(GetRoutes, TestEmptyRoutes)
29{
Nan Zhou5ad77202022-06-13 22:33:55 +000030 App app;
31 app.validate();
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070032
Nan Zhou4dd73a12022-06-13 22:38:52 +000033 EXPECT_THAT(app.getRoutes(), IsEmpty());
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070034}
35
36// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070037TEST(GetRoutes, TestOneRoute)
38{
Nan Zhou5ad77202022-06-13 22:33:55 +000039 App app;
40
Ed Tanous15a42df2023-02-09 18:08:23 -080041 BMCWEB_ROUTE(app, "/")
42 ([](const crow::Request& /*req*/,
43 const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070044
Nan Zhou5ad77202022-06-13 22:33:55 +000045 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
46 // it is fixed
47 // EXPECT_THAT(app.getRoutes(),
Nan Zhou4dd73a12022-06-13 22:38:52 +000048 // testing::ElementsAre(Pointee(Eq("/"))));
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070049}
50
51// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070052TEST(GetRoutes, TestlotsOfRoutes)
53{
Nan Zhou5ad77202022-06-13 22:33:55 +000054 App app;
Ed Tanous15a42df2023-02-09 18:08:23 -080055 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 Tanousb4a7bfa2017-04-04 17:23:00 -070067
Nan Zhou5ad77202022-06-13 22:33:55 +000068 app.validate();
69
70 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
71 // it is fixed
Nan Zhou4dd73a12022-06-13 22:38:52 +000072 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 Tanous04e438c2020-10-03 08:06:26 -070077}
Nan Zhou4dd73a12022-06-13 22:38:52 +000078} // namespace
Ed Tanous44e45182022-07-26 16:47:23 -070079} // namespace crow