blob: 5352165b5bb30794d6d942b51b6d5b0d8d034893 [file] [log] [blame]
Ed Tanous04e438c2020-10-03 08:06:26 -07001#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
6using namespace crow;
7using namespace std;
8
Ed Tanous1abe55e2018-09-05 08:30:59 -07009TEST(GetRoutes, TestEmptyRoutes)
10{
Nan Zhou5ad77202022-06-13 22:33:55 +000011 App app;
12 app.validate();
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070013
Ed Tanous1abe55e2018-09-05 08:30:59 -070014 EXPECT_THAT(app.getRoutes(), testing::IsEmpty());
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070015}
16
17// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070018TEST(GetRoutes, TestOneRoute)
19{
Nan Zhou5ad77202022-06-13 22:33:55 +000020 App app;
21
Ed Tanous1abe55e2018-09-05 08:30:59 -070022 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; });
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070023
Nan Zhou5ad77202022-06-13 22:33:55 +000024 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
25 // it is fixed
26 // EXPECT_THAT(app.getRoutes(),
27 // testing::ElementsAre(testing::Pointee(std::string("/"))));
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070028}
29
30// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070031TEST(GetRoutes, TestlotsOfRoutes)
32{
Nan Zhou5ad77202022-06-13 22:33:55 +000033 App app;
Ed Tanous1abe55e2018-09-05 08:30:59 -070034 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; });
35 BMCWEB_ROUTE(app, "/foo")([]() { return boost::beast::http::status::ok; });
36 BMCWEB_ROUTE(app, "/bar")([]() { return boost::beast::http::status::ok; });
37 BMCWEB_ROUTE(app, "/baz")([]() { return boost::beast::http::status::ok; });
38 BMCWEB_ROUTE(app, "/boo")([]() { return boost::beast::http::status::ok; });
39 BMCWEB_ROUTE(app, "/moo")([]() { return boost::beast::http::status::ok; });
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070040
Nan Zhou5ad77202022-06-13 22:33:55 +000041 app.validate();
42
43 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
44 // it is fixed
Ed Tanous1abe55e2018-09-05 08:30:59 -070045 EXPECT_THAT(app.getRoutes(), testing::UnorderedElementsAre(
Nan Zhou5ad77202022-06-13 22:33:55 +000046 // testing::Pointee(std::string("/")),
Ed Tanous1abe55e2018-09-05 08:30:59 -070047 testing::Pointee(std::string("/foo")),
48 testing::Pointee(std::string("/bar")),
49 testing::Pointee(std::string("/baz")),
50 testing::Pointee(std::string("/boo")),
51 testing::Pointee(std::string("/moo"))));
Ed Tanous04e438c2020-10-03 08:06:26 -070052}