Add unit tests for file body
File body needs some unit tests for managing the move constructors.
Tested: Unit tests pass.
Change-Id: Ia640aec75a6f3f85640a50f5dd492638871f9eca
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/test/http/http_response_test.cpp b/test/http/http_response_test.cpp
index f61d6de..c5bfbdc 100644
--- a/test/http/http_response_test.cpp
+++ b/test/http/http_response_test.cpp
@@ -1,6 +1,7 @@
#include "boost/beast/core/buffers_to_string.hpp"
#include "boost/beast/core/flat_buffer.hpp"
#include "boost/beast/http/serializer.hpp"
+#include "file_test_utilities.hpp"
#include "http/http_response.hpp"
#include <filesystem>
@@ -23,19 +24,6 @@
EXPECT_EQ(res.result(), boost::beast::http::status::ok);
}
-std::string makeFile(std::string_view sampleData)
-{
- std::filesystem::path path = std::filesystem::temp_directory_path();
- path /= "bmcweb_http_response_test_XXXXXXXXXXX";
- std::string stringPath = path.string();
- int fd = mkstemp(stringPath.data());
- EXPECT_GT(fd, 0);
- EXPECT_EQ(write(fd, sampleData.data(), sampleData.size()),
- sampleData.size());
- close(fd);
- return stringPath;
-}
-
std::string getData(boost::beast::http::response<bmcweb::FileBody>& m)
{
std::string ret;
@@ -139,6 +127,24 @@
EXPECT_EQ(getData(fb), data);
}
+std::string generateBigdata()
+{
+ std::string result;
+ while (result.size() < 10000)
+ {
+ result += "sample text";
+ }
+ return result;
+}
+
+TEST(HttpResponse, StringBodyWriterLarge)
+{
+ crow::Response res;
+ std::string data = generateBigdata();
+ res.write(std::string(data));
+ testFileData(res, data);
+}
+
TEST(HttpResponse, Base64FileBodyWriter)
{
crow::Response res;
@@ -151,16 +157,6 @@
std::filesystem::remove(path);
}
-std::string generateBigdata()
-{
- std::string result;
- while (result.size() < 10000)
- {
- result += "sample text";
- }
- return result;
-}
-
TEST(HttpResponse, Base64FileBodyWriterLarge)
{
crow::Response res;