1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #include "app.hpp" 4 #include "async_resp.hpp" 5 #include "http_request.hpp" 6 7 #include <memory> 8 9 #include <gmock/gmock.h> 10 #include <gtest/gtest.h> 11 12 namespace crow 13 { 14 namespace 15 { 16 17 using ::bmcweb::AsyncResp; 18 using ::testing::Eq; 19 using ::testing::IsEmpty; 20 using ::testing::Pointee; 21 using ::testing::UnorderedElementsAre; 22 23 TEST(GetRoutes, TestEmptyRoutes) 24 { 25 App app; 26 app.validate(); 27 28 EXPECT_THAT(app.getRoutes(), IsEmpty()); 29 } 30 31 // Tests that static urls are correctly passed 32 TEST(GetRoutes, TestOneRoute) 33 { 34 App app; 35 36 BMCWEB_ROUTE(app, "/") 37 ([](const crow::Request& /*req*/, 38 const std::shared_ptr<AsyncResp>& /*asyncResp*/) {}); 39 40 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once 41 // it is fixed 42 // EXPECT_THAT(app.getRoutes(), 43 // testing::ElementsAre(Pointee(Eq("/")))); 44 } 45 46 // Tests that static urls are correctly passed 47 TEST(GetRoutes, TestlotsOfRoutes) 48 { 49 App app; 50 BMCWEB_ROUTE(app, "/") 51 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); 52 BMCWEB_ROUTE(app, "/foo") 53 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); 54 BMCWEB_ROUTE(app, "/bar") 55 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); 56 BMCWEB_ROUTE(app, "/baz") 57 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); 58 BMCWEB_ROUTE(app, "/boo") 59 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); 60 BMCWEB_ROUTE(app, "/moo") 61 ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {}); 62 63 app.validate(); 64 65 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once 66 // it is fixed 67 EXPECT_THAT(app.getRoutes(), UnorderedElementsAre( 68 // Pointee(Eq("/")), 69 Pointee(Eq("/foo")), Pointee(Eq("/bar")), 70 Pointee(Eq("/baz")), Pointee(Eq("/boo")), 71 Pointee(Eq("/moo")))); 72 } 73 } // namespace 74 } // namespace crow 75