From: Michael Tremer Date: Wed, 1 Nov 2023 14:40:52 +0000 (+0000) Subject: tests: Add option to request a HTTP client X-Git-Tag: 0.9.30~1342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2ab26e0fe62f756cb4d0c90c567aac67635934b;p=pakfire.git tests: Add option to request a HTTP client Signed-off-by: Michael Tremer --- diff --git a/tests/testsuite.c b/tests/testsuite.c index 30ae9cd32..9a0f55d21 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -93,12 +93,25 @@ static int test_run(int i, struct test* t) { } } + // Create a HTTP client (if requested) + if (t->flags & TEST_WANTS_HTTPCLIENT) { + r = pakfire_httpclient_create(&t->httpclient, t->ctx); + if (r) { + LOG("ERROR: Could not initialize the HTTP client: %s\n", strerror(-r)); + goto ERROR; + } + } + // Run test r = t->func(t); if (r) LOG("Test failed with error code: %d\n", r); ERROR: + // Release HTTP client + if (t->httpclient) + pakfire_httpclient_unref(t->httpclient); + // Release pakfire if (t->pakfire) { p = pakfire_unref(t->pakfire); diff --git a/tests/testsuite.h b/tests/testsuite.h index 459e639fe..bce62c1d9 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -27,6 +27,7 @@ #include #include +#include #include #define MAX_TESTS 128 @@ -34,7 +35,8 @@ #define TEST_SRC_PATH ABS_TOP_SRCDIR "/tests/" enum test_flags { - TEST_WANTS_PAKFIRE = (1 << 0), + TEST_WANTS_PAKFIRE = (1 << 0), + TEST_WANTS_HTTPCLIENT = (1 << 1), }; struct test { @@ -47,6 +49,9 @@ struct test { // Pakfire struct pakfire* pakfire; + + // HTTP Client + struct pakfire_httpclient* httpclient; }; struct testsuite {