blob: 58b745b430fbecef072926c53752edab8e5b2091 [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
23using ::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 Tanous1abe55e2018-09-05 08:30:59 -070041 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; });
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070042
Nan Zhou5ad77202022-06-13 22:33:55 +000043 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
44 // it is fixed
45 // EXPECT_THAT(app.getRoutes(),
Nan Zhou4dd73a12022-06-13 22:38:52 +000046 // testing::ElementsAre(Pointee(Eq("/"))));
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070047}
48
49// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070050TEST(GetRoutes, TestlotsOfRoutes)
51{
Nan Zhou5ad77202022-06-13 22:33:55 +000052 App app;
Ed Tanous1abe55e2018-09-05 08:30:59 -070053 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; });
54 BMCWEB_ROUTE(app, "/foo")([]() { return boost::beast::http::status::ok; });
55 BMCWEB_ROUTE(app, "/bar")([]() { return boost::beast::http::status::ok; });
56 BMCWEB_ROUTE(app, "/baz")([]() { return boost::beast::http::status::ok; });
57 BMCWEB_ROUTE(app, "/boo")([]() { return boost::beast::http::status::ok; });
58 BMCWEB_ROUTE(app, "/moo")([]() { return boost::beast::http::status::ok; });
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070059
Nan Zhou5ad77202022-06-13 22:33:55 +000060 app.validate();
61
62 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
63 // it is fixed
Nan Zhou4dd73a12022-06-13 22:38:52 +000064 EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
65 // Pointee(Eq("/")),
66 Pointee(Eq("/foo")), Pointee(Eq("/bar")),
67 Pointee(Eq("/baz")), Pointee(Eq("/boo")),
68 Pointee(Eq("/moo"))));
Ed Tanous04e438c2020-10-03 08:06:26 -070069}
Nan Zhou4dd73a12022-06-13 22:38:52 +000070} // namespace
71} // namespace crow