Skip to content

Commit ee0bee3

Browse files
Fix HttpWatch tests (#2089)
HttpWatch changed the formatting of the returned JSON. Normalize it by removing all whitespace.
1 parent 71ba7e7 commit ee0bee3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

test/test.cc

+14-6
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,14 @@ TEST(CancelTest, WithCancelLargePayloadDelete) {
13611361
EXPECT_EQ(Error::Canceled, res.error());
13621362
}
13631363

1364+
static std::string remove_whitespace(const std::string &input) {
1365+
std::string output;
1366+
output.reserve(input.size());
1367+
std::copy_if(input.begin(), input.end(), std::back_inserter(output),
1368+
[](unsigned char c) { return !std::isspace(c); });
1369+
return output;
1370+
}
1371+
13641372
TEST(BaseAuthTest, FromHTTPWatch_Online) {
13651373
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
13661374
auto host = "httpbin.org";
@@ -1388,17 +1396,17 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
13881396
auto res =
13891397
cli.Get(path, {make_basic_authentication_header("hello", "world")});
13901398
ASSERT_TRUE(res);
1391-
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
1392-
res->body);
1399+
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}",
1400+
remove_whitespace(res->body));
13931401
EXPECT_EQ(StatusCode::OK_200, res->status);
13941402
}
13951403

13961404
{
13971405
cli.set_basic_auth("hello", "world");
13981406
auto res = cli.Get(path);
13991407
ASSERT_TRUE(res);
1400-
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
1401-
res->body);
1408+
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}",
1409+
remove_whitespace(res->body));
14021410
EXPECT_EQ(StatusCode::OK_200, res->status);
14031411
}
14041412

@@ -1454,8 +1462,8 @@ TEST(DigestAuthTest, FromHTTPWatch_Online) {
14541462
for (const auto &path : paths) {
14551463
auto res = cli.Get(path.c_str());
14561464
ASSERT_TRUE(res);
1457-
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
1458-
res->body);
1465+
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}",
1466+
remove_whitespace(res->body));
14591467
EXPECT_EQ(StatusCode::OK_200, res->status);
14601468
}
14611469

0 commit comments

Comments
 (0)