summaryrefslogtreecommitdiff
path: root/test/http/crow_getroutes_test.cpp
blob: 0c3f8de6083311f937c61ffa0ed8cfe01d177836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "app.hpp"
#include "async_resp.hpp"
#include "http_request.hpp"

#include <memory>

#include <gmock/gmock.h> // IWYU pragma: keep
#include <gtest/gtest.h> // IWYU pragma: keep

// IWYU pragma: no_include <gtest/gtest-message.h>
// IWYU pragma: no_include <gtest/gtest-test-part.h>
// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
// IWYU pragma: no_include <gmock/gmock-matchers.h>
// IWYU pragma: no_include <gmock/gmock-more-matchers.h>
// IWYU pragma: no_include <gtest/gtest-matchers.h>

namespace crow
{
namespace
{

using ::bmcweb::AsyncResp;
using ::testing::Eq;
using ::testing::IsEmpty;
using ::testing::Pointee;
using ::testing::UnorderedElementsAre;

TEST(GetRoutes, TestEmptyRoutes)
{
    App app;
    app.validate();

    EXPECT_THAT(app.getRoutes(), IsEmpty());
}

// Tests that static urls are correctly passed
TEST(GetRoutes, TestOneRoute)
{
    App app;

    BMCWEB_ROUTE(app, "/")
    ([](const crow::Request& /*req*/,
        const std::shared_ptr<AsyncResp>& /*asyncResp*/) {});

    // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
    // it is fixed
    // EXPECT_THAT(app.getRoutes(),
    // testing::ElementsAre(Pointee(Eq("/"))));
}

// Tests that static urls are correctly passed
TEST(GetRoutes, TestlotsOfRoutes)
{
    App app;
    BMCWEB_ROUTE(app, "/")
    ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
    BMCWEB_ROUTE(app, "/foo")
    ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
    BMCWEB_ROUTE(app, "/bar")
    ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
    BMCWEB_ROUTE(app, "/baz")
    ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
    BMCWEB_ROUTE(app, "/boo")
    ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});
    BMCWEB_ROUTE(app, "/moo")
    ([](const Request& /*req*/, const std::shared_ptr<AsyncResp>& /*res*/) {});

    app.validate();

    // TODO: "/" doesn't get reported in |getRoutes| today. Uncomment this once
    // it is fixed
    EXPECT_THAT(app.getRoutes(), UnorderedElementsAre(
                                     // Pointee(Eq("/")),
                                     Pointee(Eq("/foo")), Pointee(Eq("/bar")),
                                     Pointee(Eq("/baz")), Pointee(Eq("/boo")),
                                     Pointee(Eq("/moo"))));
}
} // namespace
} // namespace crow