diff options
author | Ed Tanous <ed@tanous.net> | 2024-03-28 00:08:59 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-11 19:38:16 +0300 |
commit | d9e89dfd49538c54d280dce3750f4af264cfd5fc (patch) | |
tree | a6884a3df21336eb24c7fbeaedf225361ca46cb2 /test | |
parent | 76b038f20fed54ff61450a175160dc0af21b3cf9 (diff) | |
download | bmcweb-d9e89dfd49538c54d280dce3750f4af264cfd5fc.tar.xz |
Simplify router
Now that we only support string types in the router we no longer need to
build a "Tag" to be used for constructing argument types. Now, we can
just track the number of arguments, which simplifies the code
significantly, and removes the need to convert to and from the tag to
parameter counts.
This in turn deletes a lot of code in the router, removing the need for
tracking tag types.
Tested: Redfish service validator passes. Unit tests pass.
Change-Id: Ide1d665dc1984552681e8c05952b38073d5e32dd
Signed-off-by: Ed Tanous <ed@tanous.net>
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) |