Enable wxWebRequest tests by default

Don't require WX_TEST_WEBREQUEST_URL environment variable to be set, but
only allow defining it to override the default https://httpbin.org value
or to disable the tests by setting it to 0.
This commit is contained in:
Vadim Zeitlin
2020-12-26 16:43:03 +01:00
parent 6a064c85d4
commit 8b632bb892

View File

@@ -27,14 +27,11 @@
#include "wx/filename.h" #include "wx/filename.h"
#include "wx/wfstream.h" #include "wx/wfstream.h"
// This test requires the URL to an httpbin instance. // This test uses https://httpbin.org by default, but this can be overridden by
// httpbin is a HTTP Request & Response Service available at: // setting WX_TEST_WEBREQUEST_URL, e.g. when running httpbin locally in a
// https://httpbin.org // docker container. This variable can also be set to a special value "0" to
// It can also be run locally via a simple docker run // disable running the test entirely.
// static const char* WX_TEST_WEBREQUEST_URL_DEFAULT = "https://httpbin.org";
// For this test to run the the base URL has to be specified with
// an environment variable, e.g.:
// WX_TEST_WEBREQUEST_URL=https://httpbin.org
class RequestFixture class RequestFixture
{ {
@@ -45,10 +42,16 @@ public:
dataSize = 0; dataSize = 0;
} }
bool InitBaseURL()
{
if ( !wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL) )
baseURL = WX_TEST_WEBREQUEST_URL_DEFAULT;
return baseURL != "0";
}
void Create(const wxString& subURL) void Create(const wxString& subURL)
{ {
wxString baseURL;
wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL);
CreateAbs(baseURL + subURL); CreateAbs(baseURL + subURL);
} }
@@ -99,21 +102,18 @@ public:
REQUIRE( request->GetResponse()->GetStatus() == requiredStatus ); REQUIRE( request->GetResponse()->GetStatus() == requiredStatus );
} }
wxString baseURL;
wxEventLoop loop; wxEventLoop loop;
wxObjectDataPtr<wxWebRequest> request; wxObjectDataPtr<wxWebRequest> request;
wxInt64 expectedFileSize; wxInt64 expectedFileSize;
wxInt64 dataSize; wxInt64 dataSize;
}; };
TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][.]") TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][webrequest]")
{ {
wxString baseURL; // Skip the test entirely if disabled.
if ( !wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL) ) if ( !InitBaseURL() )
{
WARN("Skipping WebRequest test because required WX_TEST_WEBREQUEST_URL"
" environment variable is not defined.");
return; return;
}
SECTION("GET 64kb to memory") SECTION("GET 64kb to memory")
{ {
@@ -209,7 +209,7 @@ WXDLLIMPEXP_NET wxString
SplitParameters(const wxString& s, wxWebRequestHeaderMap& parameters); SplitParameters(const wxString& s, wxWebRequestHeaderMap& parameters);
} }
TEST_CASE("WebRequestUtils", "[net]") TEST_CASE("WebRequestUtils", "[net][webrequest]")
{ {
wxString value; wxString value;
wxWebRequestHeaderMap params; wxWebRequestHeaderMap params;