@@ -46,15 +46,10 @@ TEST(HTTP, HTTPClientMoveOwnership) {
4646
4747TEST (HTTP, HTTPBodyNonEmpty) {
4848 HttpClient client{};
49- try {
50- HttpResponse request =
51- client.get (" https://postman-echo.com/get?foo=bar" ).execute ();
52- EXPECT_TRUE (request.is_ok ());
53- EXPECT_THAT (request.body (), testing::HasSubstr (" \" foo\" :\" bar\" " ));
54-
55- } catch (const std::exception &e) {
56- FAIL () << std::format (" Request failed with exception: {}" , e.what ());
57- }
49+ HttpResponse request =
50+ client.get (" https://postman-echo.com/get?foo=bar" ).execute ();
51+ EXPECT_TRUE (request.is_ok ());
52+ EXPECT_THAT (request.body (), testing::HasSubstr (" \" foo\" :\" bar\" " ));
5853}
5954
6055TEST (HTTP, HTTPHandleTimeout) {
@@ -119,17 +114,12 @@ TEST(HTTP, HTTPClientDefaultHeadersOverwrittenByRequestHeaders) {
119114 .timeout (10 )
120115 .header (" User-Agent" , val);
121116
122- try {
123- auto resp = request.execute ();
124-
125- // request should work + having the new user-agent header each time
126- EXPECT_TRUE (resp.is_ok ());
127- EXPECT_THAT (resp.body (), testing::HasSubstr (
128- std::format (" \" user-agent\" :\" {}\" " , val)));
117+ auto resp = request.execute ();
129118
130- } catch (const std::exception &e) {
131- FAIL () << std::format (" Request failed: {}" , e.what ());
132- }
119+ // request should work + having the new user-agent header each time
120+ EXPECT_TRUE (resp.is_ok ());
121+ EXPECT_THAT (resp.body (),
122+ testing::HasSubstr (std::format (" \" user-agent\" :\" {}\" " , val)));
133123 }
134124}
135125
@@ -143,17 +133,13 @@ TEST(HTTP, HTTPRemoveHeader) {
143133 // in which case, when merging request and client headers, if we remove a
144134 // request one, the client one should also be removed!
145135
146- try {
147- // Removes the User-Agent header
148- auto resp = client.get (" https://postman-echo.com/get" )
149- .timeout (10 )
150- .header (" User-Agent" , " " )
151- .execute ();
152- EXPECT_THAT (resp.body (),
153- testing::Not (testing::HasSubstr (" \" user-agent\" :\" client\" " )));
154- } catch (const std::exception &e) {
155- FAIL () << std::format (" Request failed: {}" , e.what ());
156- }
136+ // Removes the User-Agent header
137+ auto resp = client.get (" https://postman-echo.com/get" )
138+ .timeout (10 )
139+ .header (" User-Agent" , " " )
140+ .execute ();
141+ EXPECT_THAT (resp.body (),
142+ testing::Not (testing::HasSubstr (" \" user-agent\" :\" client\" " )));
157143}
158144
159145TEST (HTTP, HTTPHead) {
@@ -201,35 +187,60 @@ TEST(HTTP, HTTPHeaderOrder) {
201187
202188TEST (HTTP, HTTPPost) {
203189 HttpClient client{};
204- std::string data = " This is expected to be sent back as part of response body" ;
205- HttpBodyRequest req = client.post (" https://postman-echo.com/post" ).body (data);
190+ std::string data =
191+ " This is expected to be sent back as part of response body" ;
192+ HttpBodyRequest req = client.post (" https://postman-echo.com/post" ).body (data);
206193 EXPECT_EQ (req.getBody (), data);
207194 HttpResponse resp = req.execute ();
208195 EXPECT_TRUE (resp.is_ok ());
209196 EXPECT_EQ (resp.status (), 200 );
210- EXPECT_THAT (resp.body (), testing::HasSubstr (data));
197+ EXPECT_THAT (resp.body (), testing::HasSubstr (data));
211198}
212199
213200// NOTE(cristian): This is done at compile time, duh, nothing to check
214201/*
215202TEST(HTTP, HTTPGetHeadCRTP) {
216- // This validates our changes we did with CRTP
217- // When issuing a GET/HEAD we cannot do a .body()
218- // this is determined at compile time
219- HttpClient client{};
220- HttpRequest req = client.head("https://postman-echo.com/get?foo0=bar1&foo2=bar2");
221- // Check that we cannot do body
203+ // This validates our changes we did with CRTP
204+ // When issuing a GET/HEAD we cannot do a .body()
205+ // this is determined at compile time
206+ HttpClient client{};
207+ HttpRequest req =
208+ client.head("https://postman-echo.com/get?foo0=bar1&foo2=bar2");
209+ // Check that we cannot do body
222210}
223211*/
224212
225213TEST (HTTP, HTTPPut) {
226214 HttpClient client{};
227- std::string data = " This is expected to be sent back as part of response body" ;
228- HttpBodyRequest req = client.put (" https://postman-echo.com/post" ).body (data);
215+ std::string data =
216+ " This is expected to be sent back as part of response body" ;
217+ HttpBodyRequest req = client.put (" https://postman-echo.com/post" ).body (data);
229218 EXPECT_EQ (req.getBody (), data);
230219 HttpResponse resp = req.execute ();
231220 EXPECT_TRUE (resp.is_ok ());
232221 EXPECT_EQ (resp.status (), 200 );
233- EXPECT_THAT (resp.body (), testing::HasSubstr (data));
222+ EXPECT_THAT (resp.body (), testing::HasSubstr (data));
234223}
235224
225+ TEST (HTTP, HTTPDeleteQueryParamStr) {
226+ HttpClient client{};
227+ std::string query = " deletethis" ;
228+ HttpBodyRequest req =
229+ client.del (std::format (" https://postman-echo.com/patch?{}" , query));
230+ HttpResponse resp = req.execute ();
231+ EXPECT_TRUE (resp.is_ok ());
232+ EXPECT_EQ (resp.status (), 200 );
233+ EXPECT_THAT (resp.body (), testing::HasSubstr (query));
234+ }
235+
236+ TEST (HTTP, HTTPDeleteWithBody) {
237+ HttpClient client{};
238+ std::string data = " This is expected to be deleted" ;
239+ HttpBodyRequest req =
240+ client.del (" https://postman-echo.com/patch" ).body (data);
241+ EXPECT_EQ (req.getBody (), data);
242+ HttpResponse resp = req.execute ();
243+ EXPECT_TRUE (resp.is_ok ());
244+ EXPECT_EQ (resp.status (), 200 );
245+ EXPECT_THAT (resp.body (), testing::HasSubstr (data));
246+ }
0 commit comments