Skip to content

Commit

Permalink
feat: add one client upload twice example
Browse files Browse the repository at this point in the history
  • Loading branch information
helintongh committed Aug 10, 2023
1 parent b7a5bf1 commit d5b4be7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ TEST_CASE("test server body limit upload request body") {
// server.enable_timeout(false);

auto control_func = [](request &req, response &res) -> bool {
int max_body_size = 2048; // 1k
int max_body_size = 2048; // 2k
if (max_body_size < req.body_len()) {
return false;
}
Expand Down Expand Up @@ -989,17 +989,30 @@ TEST_CASE("test server body limit upload request body") {
coro_http_client client{};
std::string uri = "http://127.0.0.1:8090/multipart";

client.set_max_single_part_size(2048);
client.set_max_single_part_size(1024);

std::string test_file_name = "test1.txt";
std::ofstream test_file;
test_file.open(test_file_name,
std::ios::binary | std::ios::out | std::ios::trunc);
std::vector<char> test_file_data(10 * 1024 * 1024, '0');
std::vector<char> test_file_data(1 * 1024, '0');
test_file.write(test_file_data.data(), test_file_data.size());
test_file.close();
auto result = async_simple::coro::syncAwait(
client.async_upload_multipart(uri, "test", test_file_name));

CHECK(result.status == 200);
client.set_max_single_part_size(2048);
std::string test_big_file_name = "test_2mb.txt";
std::ofstream test_big_file;
test_big_file.open(test_big_file_name,
std::ios::binary | std::ios::out | std::ios::trunc);
std::vector<char> test_big_file_data(3 * 1024 * 1024, '0');
test_big_file.write(test_big_file_data.data(), test_big_file_data.size());
test_big_file.close();
result = async_simple::coro::syncAwait(
client.async_upload_multipart(uri, "test_big", test_big_file_name));

CHECK(result.status == 404);

coro_http_client sec_client{};
Expand All @@ -1012,7 +1025,7 @@ TEST_CASE("test server body limit upload request body") {
small_file.write(small_file_data.data(), small_file_data.size());
small_file.close();
result = async_simple::coro::syncAwait(
sec_client.async_upload_multipart(uri, "test", small_file_name));
sec_client.async_upload_multipart(uri, "test_small", small_file_name));
CHECK(result.status == 200);
CHECK(result.resp_body == "multipart finished");

Expand Down

0 comments on commit d5b4be7

Please sign in to comment.