diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/http/router_test.cpp | 35 | ||||
-rw-r--r-- | test/http/utility_test.cpp | 5 |
2 files changed, 39 insertions, 1 deletions
diff --git a/test/http/router_test.cpp b/test/http/router_test.cpp index edd9054f6c..f23331782b 100644 --- a/test/http/router_test.cpp +++ b/test/http/router_test.cpp @@ -62,6 +62,41 @@ TEST(Router, AllowHeader) EXPECT_NE(router.findRoute(patchReq).route.rule, nullptr); } +TEST(Router, OverlapingRoutes) +{ + // Callback handler that does nothing + auto fooCallback = [](const Request&, + const std::shared_ptr<bmcweb::AsyncResp>&) { + EXPECT_FALSE(true); + }; + bool barCalled = false; + auto foobarCallback = + [&barCalled](const Request&, const std::shared_ptr<bmcweb::AsyncResp>&, + const std::string& bar) { + barCalled = true; + EXPECT_EQ(bar, "bar"); + }; + + Router router; + std::error_code ec; + + router.newRuleTagged<getParameterTag("/foo/<str>")>("/foo/<str>")( + foobarCallback); + router.newRuleTagged<getParameterTag("/foo")>("/foo")(fooCallback); + router.validate(); + { + constexpr std::string_view url = "/foo/bar"; + + Request req{{boost::beast::http::verb::get, url, 11}, ec}; + + std::shared_ptr<bmcweb::AsyncResp> asyncResp = + std::make_shared<bmcweb::AsyncResp>(); + + router.handle(req, asyncResp); + } + EXPECT_TRUE(barCalled); +} + TEST(Router, 404) { bool notFoundCalled = false; diff --git a/test/http/utility_test.cpp b/test/http/utility_test.cpp index 411ecebcb4..f5ae5b1b5e 100644 --- a/test/http/utility_test.cpp +++ b/test/http/utility_test.cpp @@ -163,7 +163,10 @@ TEST(Router, ParameterTagging) { EXPECT_EQ(1, getParameterTag("<str>")); EXPECT_EQ(1, getParameterTag("<string>")); - EXPECT_EQ(2, getParameterTag("<path>")); + EXPECT_EQ(1, getParameterTag("<path>")); + EXPECT_EQ(2, getParameterTag("<str>/<str>")); + EXPECT_EQ(2, getParameterTag("<string>/<string>")); + EXPECT_EQ(2, getParameterTag("<path>/<path>")); } TEST(URL, JsonEncoding) |