blob: 21bbbd1f3a0a9b84aaba463ca0bfa859616330ff [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Nan Zhou4dd73a12022-06-13 22:38:52 +00003#include "app.hpp"
Ed Tanousf0b59af2024-03-20 13:38:04 -07004#include "async_resp.hpp"
5#include "http_request.hpp"
Nan Zhoud5c80ad2022-07-11 01:16:31 +00006
7#include <memory>
8
Ed Tanous478b7ad2024-07-15 19:11:54 -07009#include <gmock/gmock.h>
10#include <gtest/gtest.h>
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070011
Nan Zhou4dd73a12022-06-13 22:38:52 +000012namespace crow
13{
14namespace
15{
16
Ed Tanous15a42df2023-02-09 18:08:23 -080017using ::bmcweb::AsyncResp;
Nan Zhou4dd73a12022-06-13 22:38:52 +000018using ::testing::Eq;
19using ::testing::IsEmpty;
20using ::testing::Pointee;
21using ::testing::UnorderedElementsAre;
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070022
Ed Tanous1abe55e2018-09-05 08:30:59 -070023TEST(GetRoutes, TestEmptyRoutes)
24{
Nan Zhou5ad77202022-06-13 22:33:55 +000025 App app;
26 app.validate();
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070027
Nan Zhou4dd73a12022-06-13 22:38:52 +000028 EXPECT_THAT(app.getRoutes(), IsEmpty());
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070029}
30
31// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070032TEST(GetRoutes, TestOneRoute)
33{
Nan Zhou5ad77202022-06-13 22:33:55 +000034 App app;
35
Ed Tanous15a42df2023-02-09 18:08:23 -080036 BMCWEB_ROUTE(app, "/")
37 ([](const crow::Request& /*req*/,
38 const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070039
Nan Zhou5ad77202022-06-13 22:33:55 +000040 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
41 // it is fixed
42 // EXPECT_THAT(app.getRoutes(),
Nan Zhou4dd73a12022-06-13 22:38:52 +000043 // testing::ElementsAre(Pointee(Eq("/"))));
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070044}
45
46// Tests that static urls are correctly passed
Ed Tanous1abe55e2018-09-05 08:30:59 -070047TEST(GetRoutes, TestlotsOfRoutes)
48{
Nan Zhou5ad77202022-06-13 22:33:55 +000049 App app;
Ed Tanous15a42df2023-02-09 18:08:23 -080050 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*/) {});
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070062
Nan Zhou5ad77202022-06-13 22:33:55 +000063 app.validate();
64
65 // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
66 // it is fixed
Nan Zhou4dd73a12022-06-13 22:38:52 +000067 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"))));
Ed Tanous04e438c2020-10-03 08:06:26 -070072}
Nan Zhou4dd73a12022-06-13 22:38:52 +000073} // namespace
Ed Tanous44e45182022-07-26 16:47:23 -070074} // namespace crow