blob: 698e39cbd14be8006542a6941792ea4f0d5ea417 [file] [log] [blame]
Ed Tanous2c9efc32022-07-31 22:08:26 -07001#include "verb.hpp"
2
3#include <boost/beast/http/verb.hpp>
4
5#include <map>
6#include <optional>
7#include <string_view>
8
9#include <gtest/gtest.h> // IWYU pragma: keep
10
11using BoostVerb = boost::beast::http::verb;
12
13TEST(BoostToHttpVerb, ValidCase)
14{
15 std::map<HttpVerb, BoostVerb> verbMap = {
16 {HttpVerb::Delete, BoostVerb::delete_},
17 {HttpVerb::Get, BoostVerb::get},
18 {HttpVerb::Head, BoostVerb::head},
19 {HttpVerb::Options, BoostVerb::options},
20 {HttpVerb::Patch, BoostVerb::patch},
21 {HttpVerb::Post, BoostVerb::post},
22 {HttpVerb::Put, BoostVerb::put},
23 };
24
25 for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
26 ++verbIndex)
27 {
28 HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
29 std::optional<HttpVerb> verb = httpVerbFromBoost(verbMap[httpVerb]);
Ed Tanouse01d0c32023-06-30 13:21:32 -070030 EXPECT_EQ(verb, httpVerb);
Ed Tanous2c9efc32022-07-31 22:08:26 -070031 }
32}
33
34TEST(BoostToHttpVerbTest, InvalidCase)
35{
36 std::optional<HttpVerb> verb = httpVerbFromBoost(BoostVerb::unknown);
37 EXPECT_FALSE(verb.has_value());
38}
39
40TEST(HttpVerbToStringTest, ValidCase)
41{
42 std::map<HttpVerb, std::string_view> verbMap = {
43 {HttpVerb::Delete, "DELETE"}, {HttpVerb::Get, "GET"},
44 {HttpVerb::Head, "HEAD"}, {HttpVerb::Options, "OPTIONS"},
45 {HttpVerb::Patch, "PATCH"}, {HttpVerb::Post, "POST"},
46 {HttpVerb::Put, "PUT"},
47 };
48
49 for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
50 ++verbIndex)
51 {
52 HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
53 EXPECT_EQ(httpVerbToString(httpVerb), verbMap[httpVerb]);
54 }
Patrick Williams89492a12023-05-10 07:51:34 -050055}