blob: f4d375b35b5dcb40bbdef50707196bc04417afa8 [file] [log] [blame]
Nan Zhou4dd73a12022-06-13 22:38:52 +00001#include "app.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -07002
Ed Tanousb4a7bfa2017-04-04 17:23:00 -07003#include "gmock/gmock.h"
4#include "gtest/gtest.h"
5
Nan Zhou4dd73a12022-06-13 22:38:52 +00006namespace crow
7{
8namespace
9{
10
11using ::testing::Eq;
12using ::testing::IsEmpty;
13using ::testing::Pointee;
14using ::testing::UnorderedElementsAre;
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070015
Ed Tanous1abe55e2018-09-05 08:30:59 -070016TEST(GetRoutes, TestEmptyRoutes)
17{
Nan Zhou5ad77202022-06-13 22:33:55 +000018 App app;
19 app.validate();
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070020
Nan Zhou4dd73a12022-06-13 22:38:52 +000021 EXPECT_THAT(app.getRoutes(), IsEmpty());
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070022}
23
24// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070025TEST(GetRoutes, TestOneRoute)
26{
Nan Zhou5ad77202022-06-13 22:33:55 +000027 App app;
28
Ed Tanous1abe55e2018-09-05 08:30:59 -070029 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; });
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070030
Nan Zhou5ad77202022-06-13 22:33:55 +000031 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
32 // it is fixed
33 // EXPECT_THAT(app.getRoutes(),
Nan Zhou4dd73a12022-06-13 22:38:52 +000034 // testing::ElementsAre(Pointee(Eq("/"))));
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, TestlotsOfRoutes)
39{
Nan Zhou5ad77202022-06-13 22:33:55 +000040 App app;
Ed Tanous1abe55e2018-09-05 08:30:59 -070041 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; });
42 BMCWEB_ROUTE(app, "/foo")([]() { return boost::beast::http::status::ok; });
43 BMCWEB_ROUTE(app, "/bar")([]() { return boost::beast::http::status::ok; });
44 BMCWEB_ROUTE(app, "/baz")([]() { return boost::beast::http::status::ok; });
45 BMCWEB_ROUTE(app, "/boo")([]() { return boost::beast::http::status::ok; });
46 BMCWEB_ROUTE(app, "/moo")([]() { return boost::beast::http::status::ok; });
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070047
Nan Zhou5ad77202022-06-13 22:33:55 +000048 app.validate();
49
50 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
51 // it is fixed
Nan Zhou4dd73a12022-06-13 22:38:52 +000052 EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
53 // Pointee(Eq("/")),
54 Pointee(Eq("/foo")), Pointee(Eq("/bar")),
55 Pointee(Eq("/baz")), Pointee(Eq("/boo")),
56 Pointee(Eq("/moo"))));
Ed Tanous04e438c2020-10-03 08:06:26 -070057}
Nan Zhou4dd73a12022-06-13 22:38:52 +000058} // namespace
59} // namespace crow