summaryrefslogtreecommitdiff
path: root/test/http
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-08-01 08:08:26 +0300
committerEd Tanous <ed@tanous.net>2022-12-06 02:18:32 +0300
commit2c9efc3cb140e5c1d4d57b73f0a511880ac7a11f (patch)
tree41700c098e51c56cdc107df78c82b14b6d429b9f /test/http
parentddfc67521c537c372d54bc662c74c6e6b73be1c9 (diff)
downloadbmcweb-2c9efc3cb140e5c1d4d57b73f0a511880ac7a11f.tar.xz
Make router take up less space for verbs
As is, the router designates routes for every possible boost verb, of which there are 31. In bmcweb, we only make use of 6 of those verbs, so that ends up being quite a bit of wasted space and cache non-locality. This commit invents a new enum class for declaring a subset of boost verbs that we support, and a mapping between bmcweb verbs and boost verbs. Then it walks through and updates the router to support converting one to another. Tested: Unit Tested Redfish Service Validator performed on future commit Signed-off-by: Ed Tanous <edtanous@google.com> Signed-off-by: Edward Lee <edwarddl@google.com> Change-Id: I3c89e896c632a5d4134dbd08a30b313c12a60de6
Diffstat (limited to 'test/http')
-rw-r--r--test/http/verb_test.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/http/verb_test.cpp b/test/http/verb_test.cpp
new file mode 100644
index 0000000000..76dd8d0fb1
--- /dev/null
+++ b/test/http/verb_test.cpp
@@ -0,0 +1,56 @@
+#include "verb.hpp"
+
+#include <boost/beast/http/verb.hpp>
+
+#include <map>
+#include <optional>
+#include <string_view>
+
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+using BoostVerb = boost::beast::http::verb;
+
+TEST(BoostToHttpVerb, ValidCase)
+{
+ std::map<HttpVerb, BoostVerb> verbMap = {
+ {HttpVerb::Delete, BoostVerb::delete_},
+ {HttpVerb::Get, BoostVerb::get},
+ {HttpVerb::Head, BoostVerb::head},
+ {HttpVerb::Options, BoostVerb::options},
+ {HttpVerb::Patch, BoostVerb::patch},
+ {HttpVerb::Post, BoostVerb::post},
+ {HttpVerb::Put, BoostVerb::put},
+ };
+
+ for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
+ ++verbIndex)
+ {
+ HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
+ std::optional<HttpVerb> verb = httpVerbFromBoost(verbMap[httpVerb]);
+ ASSERT_TRUE(verb.has_value());
+ EXPECT_EQ(*verb, httpVerb);
+ }
+}
+
+TEST(BoostToHttpVerbTest, InvalidCase)
+{
+ std::optional<HttpVerb> verb = httpVerbFromBoost(BoostVerb::unknown);
+ EXPECT_FALSE(verb.has_value());
+}
+
+TEST(HttpVerbToStringTest, ValidCase)
+{
+ std::map<HttpVerb, std::string_view> verbMap = {
+ {HttpVerb::Delete, "DELETE"}, {HttpVerb::Get, "GET"},
+ {HttpVerb::Head, "HEAD"}, {HttpVerb::Options, "OPTIONS"},
+ {HttpVerb::Patch, "PATCH"}, {HttpVerb::Post, "POST"},
+ {HttpVerb::Put, "PUT"},
+ };
+
+ for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
+ ++verbIndex)
+ {
+ HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
+ EXPECT_EQ(httpVerbToString(httpVerb), verbMap[httpVerb]);
+ }
+} \ No newline at end of file