blob: e5c9d6eb7e46e2f4f57961227ac87db7a8a86409 [file] [log] [blame]
Nan Zhou4dd73a12022-06-13 22:38:52 +00001#include "app.hpp"
Nan Zhoud5c80ad2022-07-11 01:16:31 +00002#include "routing.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -07003
Nan Zhoud5c80ad2022-07-11 01:16:31 +00004#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 Tanousb4a7bfa2017-04-04 17:23:00 -070017
Nan Zhou4dd73a12022-06-13 22:38:52 +000018namespace crow
19{
20namespace
21{
22
Ed Tanous15a42df2023-02-09 18:08:23 -080023using ::bmcweb::AsyncResp;
Nan Zhou4dd73a12022-06-13 22:38:52 +000024using ::testing::Eq;
25using ::testing::IsEmpty;
26using ::testing::Pointee;
27using ::testing::UnorderedElementsAre;
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070028
Ed Tanous1abe55e2018-09-05 08:30:59 -070029TEST(GetRoutes, TestEmptyRoutes)
30{
Nan Zhou5ad77202022-06-13 22:33:55 +000031 App app;
32 app.validate();
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070033
Nan Zhou4dd73a12022-06-13 22:38:52 +000034 EXPECT_THAT(app.getRoutes(), IsEmpty());
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070035}
36
37// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070038TEST(GetRoutes, TestOneRoute)
39{
Nan Zhou5ad77202022-06-13 22:33:55 +000040 App app;
41
Ed Tanous15a42df2023-02-09 18:08:23 -080042 BMCWEB_ROUTE(app, "/")
43 ([](const crow::Request& /*req*/,
44 const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070045
Nan Zhou5ad77202022-06-13 22:33:55 +000046 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
47 // it is fixed
48 // EXPECT_THAT(app.getRoutes(),
Nan Zhou4dd73a12022-06-13 22:38:52 +000049 // testing::ElementsAre(Pointee(Eq("/"))));
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070050}
51
52// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070053TEST(GetRoutes, TestlotsOfRoutes)
54{
Nan Zhou5ad77202022-06-13 22:33:55 +000055 App app;
Ed Tanous15a42df2023-02-09 18:08:23 -080056 BMCWEB_ROUTE(app, "/")
57 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
58 BMCWEB_ROUTE(app, "/foo")
59 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
60 BMCWEB_ROUTE(app, "/bar")
61 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
62 BMCWEB_ROUTE(app, "/baz")
63 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
64 BMCWEB_ROUTE(app, "/boo")
65 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
66 BMCWEB_ROUTE(app, "/moo")
67 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070068
Nan Zhou5ad77202022-06-13 22:33:55 +000069 app.validate();
70
71 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
72 // it is fixed
Nan Zhou4dd73a12022-06-13 22:38:52 +000073 EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
74 // Pointee(Eq("/")),
75 Pointee(Eq("/foo")), Pointee(Eq("/bar")),
76 Pointee(Eq("/baz")), Pointee(Eq("/boo")),
77 Pointee(Eq("/moo"))));
Ed Tanous04e438c2020-10-03 08:06:26 -070078}
Nan Zhou4dd73a12022-06-13 22:38:52 +000079} // namespace
Ed Tanous44e45182022-07-26 16:47:23 -070080} // namespace crow