mirror of
https://github.com/BlackMATov/curly.hpp.git
synced 2025-12-15 12:19:47 +07:00
rename perfrom to send and update to perform
This commit is contained in:
@@ -48,10 +48,10 @@ namespace
|
||||
}
|
||||
|
||||
TEST_CASE("curly"){
|
||||
net::auto_updater updater;
|
||||
net::auto_performer performer;
|
||||
|
||||
SECTION("wait") {
|
||||
auto req = net::request_builder("https://httpbin.org/delay/1").perform();
|
||||
auto req = net::request_builder("https://httpbin.org/delay/1").send();
|
||||
REQUIRE(req.status() == net::request::statuses::pending);
|
||||
REQUIRE(req.wait() == net::request::statuses::done);
|
||||
REQUIRE(req.status() == net::request::statuses::done);
|
||||
@@ -61,7 +61,7 @@ TEST_CASE("curly"){
|
||||
}
|
||||
|
||||
SECTION("error") {
|
||||
auto req = net::request_builder("|||").perform();
|
||||
auto req = net::request_builder("|||").send();
|
||||
REQUIRE(req.wait() == net::request::statuses::failed);
|
||||
REQUIRE(req.status() == net::request::statuses::failed);
|
||||
REQUIRE_FALSE(req.error().empty());
|
||||
@@ -69,13 +69,13 @@ TEST_CASE("curly"){
|
||||
|
||||
SECTION("cancel") {
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/delay/1").perform();
|
||||
auto req = net::request_builder("https://httpbin.org/delay/1").send();
|
||||
REQUIRE(req.cancel());
|
||||
REQUIRE(req.status() == net::request::statuses::canceled);
|
||||
REQUIRE(req.error().empty());
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/status/200").perform();
|
||||
auto req = net::request_builder("https://httpbin.org/status/200").send();
|
||||
REQUIRE(req.wait() == net::request::statuses::done);
|
||||
REQUIRE_FALSE(req.cancel());
|
||||
REQUIRE(req.status() == net::request::statuses::done);
|
||||
@@ -85,13 +85,13 @@ TEST_CASE("curly"){
|
||||
|
||||
SECTION("get") {
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/status/204").perform();
|
||||
auto req = net::request_builder("https://httpbin.org/status/204").send();
|
||||
auto resp = req.get();
|
||||
REQUIRE(req.status() == net::request::statuses::empty);
|
||||
REQUIRE(resp.code() == 204u);
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/delay/2").perform();
|
||||
auto req = net::request_builder("https://httpbin.org/delay/2").send();
|
||||
REQUIRE(req.cancel());
|
||||
REQUIRE_THROWS_AS(req.get(), net::exception);
|
||||
REQUIRE(req.status() == net::request::statuses::canceled);
|
||||
@@ -99,7 +99,7 @@ TEST_CASE("curly"){
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/delay/2")
|
||||
.response_timeout(net::time_sec_t(0))
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.wait() == net::request::statuses::timeout);
|
||||
REQUIRE_THROWS_AS(req.get(), net::exception);
|
||||
REQUIRE(req.status() == net::request::statuses::timeout);
|
||||
@@ -111,75 +111,75 @@ TEST_CASE("curly"){
|
||||
auto req0 = net::request_builder()
|
||||
.url("https://httpbin.org/put")
|
||||
.method(net::methods::put)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req0.get().code() == 200u);
|
||||
|
||||
auto req1 = net::request_builder()
|
||||
.url("https://httpbin.org/put")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req1.get().code() == 405u);
|
||||
|
||||
auto req2 = net::request_builder()
|
||||
.url("https://httpbin.org/put")
|
||||
.method(net::methods::head)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req2.get().code() == 405u);
|
||||
|
||||
auto req3 = net::request_builder()
|
||||
.url("https://httpbin.org/put")
|
||||
.method(net::methods::post)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req3.get().code() == 405u);
|
||||
}
|
||||
{
|
||||
auto req0 = net::request_builder()
|
||||
.url("https://httpbin.org/get")
|
||||
.method(net::methods::put)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req0.get().code() == 405u);
|
||||
|
||||
auto req1 = net::request_builder()
|
||||
.url("https://httpbin.org/get")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req1.get().code() == 200u);
|
||||
|
||||
auto req2 = net::request_builder()
|
||||
.url("https://httpbin.org/get")
|
||||
.method(net::methods::head)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req2.get().code() == 200u);
|
||||
|
||||
auto req3 = net::request_builder()
|
||||
.url("https://httpbin.org/get")
|
||||
.method(net::methods::post)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req3.get().code() == 405u);
|
||||
}
|
||||
{
|
||||
auto req0 = net::request_builder()
|
||||
.url("https://httpbin.org/post")
|
||||
.method(net::methods::put)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req0.get().code() == 405u);
|
||||
|
||||
auto req1 = net::request_builder()
|
||||
.url("https://httpbin.org/post")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req1.get().code() == 405u);
|
||||
|
||||
auto req2 = net::request_builder()
|
||||
.url("https://httpbin.org/post")
|
||||
.method(net::methods::head)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req2.get().code() == 405u);
|
||||
|
||||
auto req3 = net::request_builder()
|
||||
.url("https://httpbin.org/post")
|
||||
.method(net::methods::post)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req3.get().code() == 200u);
|
||||
}
|
||||
}
|
||||
@@ -189,28 +189,28 @@ TEST_CASE("curly"){
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/status/200")
|
||||
.method(net::methods::put)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 200u);
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/status/201")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 201u);
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/status/202")
|
||||
.method(net::methods::head)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 202u);
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/status/203")
|
||||
.method(net::methods::post)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 203u);
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ TEST_CASE("curly"){
|
||||
.url("https://httpbin.org/headers")
|
||||
.header("Custom-Header-1", "custom_header_value_1")
|
||||
.header("Custom-Header-2", "custom header value 2")
|
||||
.perform();
|
||||
.send();
|
||||
const auto resp = req.get();
|
||||
const auto content_j = json::parse(resp.content().as_string_view());
|
||||
REQUIRE(content_j["headers"]["Custom-Header-1"] == "custom_header_value_1");
|
||||
@@ -232,7 +232,7 @@ TEST_CASE("curly"){
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/response-headers?hello=world&world=hello")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
const auto resp = req.get();
|
||||
const auto content_j = json::parse(resp.content().as_string_view());
|
||||
REQUIRE(content_j["hello"] == "world");
|
||||
@@ -242,7 +242,7 @@ TEST_CASE("curly"){
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/response-headers?hello=world&world=hello")
|
||||
.method(net::methods::post)
|
||||
.perform();
|
||||
.send();
|
||||
const auto resp = req.get();
|
||||
const auto content_j = json::parse(resp.content().as_string_view());
|
||||
REQUIRE(content_j["hello"] == "world");
|
||||
@@ -254,7 +254,7 @@ TEST_CASE("curly"){
|
||||
{
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/base64/SFRUUEJJTiBpcyBhd2Vzb21l")
|
||||
.perform();
|
||||
.send();
|
||||
const auto resp = req.get();
|
||||
REQUIRE(resp.content().as_string_view() == "HTTPBIN is awesome");
|
||||
REQUIRE(req.error().empty());
|
||||
@@ -263,7 +263,7 @@ TEST_CASE("curly"){
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/delay/10")
|
||||
.response_timeout(net::time_sec_t(0))
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.wait() == net::request::statuses::timeout);
|
||||
REQUIRE_FALSE(req.error().empty());
|
||||
}
|
||||
@@ -271,7 +271,7 @@ TEST_CASE("curly"){
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/delay/10")
|
||||
.response_timeout(net::time_sec_t(1))
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.wait() == net::request::statuses::timeout);
|
||||
REQUIRE_FALSE(req.error().empty());
|
||||
}
|
||||
@@ -282,7 +282,7 @@ TEST_CASE("curly"){
|
||||
auto resp = net::request_builder()
|
||||
.url("https://httpbin.org/image/png")
|
||||
.method(net::methods::get)
|
||||
.perform().get();
|
||||
.send().get();
|
||||
REQUIRE(resp.code() == 200u);
|
||||
REQUIRE(resp.headers().count("Content-Type"));
|
||||
REQUIRE(resp.headers().at("Content-Type") == "image/png");
|
||||
@@ -293,7 +293,7 @@ TEST_CASE("curly"){
|
||||
auto resp = net::request_builder()
|
||||
.url("https://httpbin.org/image/jpeg")
|
||||
.method(net::methods::get)
|
||||
.perform().get();
|
||||
.send().get();
|
||||
REQUIRE(resp.code() == 200u);
|
||||
REQUIRE(resp.headers().count("Content-Type"));
|
||||
REQUIRE(resp.headers().at("Content-Type") == "image/jpeg");
|
||||
@@ -307,21 +307,21 @@ TEST_CASE("curly"){
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/redirect/2")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 200u);
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/absolute-redirect/2")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 200u);
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder()
|
||||
.url("https://httpbin.org/relative-redirect/2")
|
||||
.method(net::methods::get)
|
||||
.perform();
|
||||
.send();
|
||||
REQUIRE(req.get().code() == 200u);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ TEST_CASE("curly"){
|
||||
.method(net::methods::put)
|
||||
.header("Content-Type", "application/json")
|
||||
.content(R"({"hello":"world"})")
|
||||
.perform().get();
|
||||
.send().get();
|
||||
const auto content_j = json::parse(resp.content().as_string_view());
|
||||
REQUIRE(content_j["data"] == R"({"hello":"world"})");
|
||||
}
|
||||
@@ -343,7 +343,7 @@ TEST_CASE("curly"){
|
||||
.method(net::methods::post)
|
||||
.header("Content-Type", "application/json")
|
||||
.content(R"({"hello":"world"})")
|
||||
.perform().get();
|
||||
.send().get();
|
||||
const auto content_j = json::parse(resp.content().as_string_view());
|
||||
REQUIRE(content_j["data"] == R"({"hello":"world"})");
|
||||
}
|
||||
@@ -353,7 +353,7 @@ TEST_CASE("curly"){
|
||||
.method(net::methods::post)
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.content("hello=world&world=hello")
|
||||
.perform().get();
|
||||
.send().get();
|
||||
const auto content_j = json::parse(resp.content().as_string_view());
|
||||
REQUIRE(content_j["form"]["hello"] == "world");
|
||||
REQUIRE(content_j["form"]["world"] == "hello");
|
||||
|
||||
Reference in New Issue
Block a user