]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add option to request a HTTP client
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Nov 2023 14:40:52 +0000 (14:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Nov 2023 14:40:52 +0000 (14:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/testsuite.c
tests/testsuite.h

index 30ae9cd32c5186e60582e925454b68fafeff640f..9a0f55d21b3b28d6f76d70231552b5e08f272353 100644 (file)
@@ -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);
index 459e639fe00b45a582f469da0609afa124ea4194..bce62c1d9a9d50b8fbbd81dda58c73ab0c2ff41b 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 
 #include <pakfire/ctx.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/pakfire.h>
 
 #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 {