1 #include "app.hpp" 2 #include "routing.hpp" 3 4 #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> 17 18 namespace crow 19 { 20 namespace 21 { 22 23 using ::testing::Eq; 24 using ::testing::IsEmpty; 25 using ::testing::Pointee; 26 using ::testing::UnorderedElementsAre; 27 28 TEST(GetRoutes, TestEmptyRoutes) 29 { 30 App app; 31 app.validate(); 32 33 EXPECT_THAT(app.getRoutes(), IsEmpty()); 34 } 35 36 // Tests that static urls are correctly passed 37 TEST(GetRoutes, TestOneRoute) 38 { 39 App app; 40 41 BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); 42 43 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once 44 // it is fixed 45 // EXPECT_THAT(app.getRoutes(), 46 // testing::ElementsAre(Pointee(Eq("/")))); 47 } 48 49 // Tests that static urls are correctly passed 50 TEST(GetRoutes, TestlotsOfRoutes) 51 { 52 App app; 53 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; }); 59 60 app.validate(); 61 62 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once 63 // it is fixed 64 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")))); 69 } 70 } // namespace 71 } // namespace crow 72