From 8d01aaf783b2237031c759a0d8e0f25eb00aefd8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 6 Mar 2021 14:44:56 +0100 Subject: [PATCH] Make WebRequest::Get::Param unit test more forgiving The simple test added in 59a8f26b01 (Add a unit test for wxWebRequest query using URL parameters, 2021-03-06) worked when using httpbin.org, but not when running httpbin locally, as it doesn't pretty-print JSON by default. Skip optional whitespace to make it work in both cases. --- tests/net/webrequest.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/net/webrequest.cpp b/tests/net/webrequest.cpp index dfb0465183..b8c8de79a9 100644 --- a/tests/net/webrequest.cpp +++ b/tests/net/webrequest.cpp @@ -223,8 +223,21 @@ TEST_CASE_METHOD(RequestFixture, // We ought to really parse the returned JSON object, but to keep things as // simple as possible for now we just treat it as a string. - CHECK_THAT( request.GetResponse().AsString().ToStdString(), - Catch::Contains("\"pi\": \"3.14159265358979323\"") ); + const wxString& response = request.GetResponse().AsString(); + INFO("Response: " << response); + + const char* expectedKey = "\"pi\":"; + size_t pos = response.find(expectedKey); + REQUIRE( pos != wxString::npos ); + + pos += strlen(expectedKey); + + // There may, or not, be a space after it. + while ( wxIsspace(response[pos]) ) + pos++; + + const char* expectedValue = "\"3.14159265358979323\""; + REQUIRE( response.compare(pos, strlen(expectedValue), expectedValue) == 0 ); } TEST_CASE_METHOD(RequestFixture,