summaryrefslogtreecommitdiff
path: root/test/http/http_body_test.cpp
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2024-01-30 20:25:03 +0300
committerEd Tanous <ed@tanous.net>2024-04-02 06:25:33 +0300
commit5575efb61318a29b810b841390dce5b80cbeacfb (patch)
tree5965e70ac529144cd8b5bf6734fc395cf74ce31e /test/http/http_body_test.cpp
parent51bd2d8a8b9d73d4e86981c0d68056aa9e2c76b2 (diff)
downloadbmcweb-5575efb61318a29b810b841390dce5b80cbeacfb.tar.xz
Create TemporaryFileHandle class
TemporaryFileHandle class is used to create temp files in the filesystem, and hold a handle to them until the class goes out of scope, at which time they can be removed. It replaces makeFile(), which was not RAII safe if an exception gets thrown, and could potentially leave files in the filesystem if the tests fail. Tested: Unit tests pass Change-Id: I03eb0d342a6cd7b78115a8c42be9175f30c4ccd0 Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'test/http/http_body_test.cpp')
-rw-r--r--test/http/http_body_test.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/test/http/http_body_test.cpp b/test/http/http_body_test.cpp
index 0983c1d815..d8c9dd1919 100644
--- a/test/http/http_body_test.cpp
+++ b/test/http/http_body_test.cpp
@@ -67,9 +67,10 @@ TEST(HttpHttpBodyValueType, CopyOperatorString)
TEST(HttpHttpBodyValueType, MoveFile)
{
HttpBody::value_type value(EncodingType::Base64);
- std::string filepath = makeFile("teststring");
+ TemporaryFileHandle temporaryFile("teststring");
boost::system::error_code ec;
- value.open(filepath.c_str(), boost::beast::file_mode::read, ec);
+ value.open(temporaryFile.stringPath.c_str(), boost::beast::file_mode::read,
+ ec);
ASSERT_FALSE(ec);
// Move constructor
HttpBody::value_type value2(std::move(value));
@@ -90,9 +91,10 @@ TEST(HttpHttpBodyValueType, MoveFile)
TEST(HttpHttpBodyValueType, MoveOperatorFile)
{
HttpBody::value_type value(EncodingType::Base64);
- std::string filepath = makeFile("teststring");
+ TemporaryFileHandle temporaryFile("teststring");
boost::system::error_code ec;
- value.open(filepath.c_str(), boost::beast::file_mode::read, ec);
+ value.open(temporaryFile.stringPath.c_str(), boost::beast::file_mode::read,
+ ec);
ASSERT_FALSE(ec);
// Move constructor
HttpBody::value_type value2 = std::move(value);
@@ -109,13 +111,12 @@ TEST(HttpHttpBodyValueType, MoveOperatorFile)
EXPECT_EQ(value2.payloadSize(), 16);
}
-TEST(HttpBodyValueType, SetFd)
+TEST(HttpFileBodyValueType, SetFd)
{
HttpBody::value_type value(EncodingType::Base64);
- std::string filepath = makeFile("teststring");
-
+ TemporaryFileHandle temporaryFile("teststring");
boost::system::error_code ec;
- value.setFd(fileno(fopen(filepath.c_str(), "r")), ec);
+ value.setFd(fileno(fopen(temporaryFile.stringPath.c_str(), "r")), ec);
ASSERT_FALSE(ec);
std::array<char, 4096> buffer{};