]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Always globally load the test configuration file
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Jan 2025 16:31:21 +0000 (16:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Jan 2025 16:31:21 +0000 (16:31 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/testsuite.c
tests/testsuite.h

index d027a020e949f0b9e6f89d8a2a36142faf41ef60..a8dc9caf7ce82554f354afc7d1e19bf792fec979 100644 (file)
@@ -1164,7 +1164,7 @@ TESTSUITE_CPPFLAGS = \
        $(AM_CPPFLAGS) \
        -I$(top_srcdir)/src \
        -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\" \
-       -DTEST_CONFIG_FILE=\"$(abs_top_srcdir)/contrib/config/pakfire.conf\" \
+       -DTEST_CONFIG_FILE=\"$(abs_top_srcdir)/tests/pakfire.conf\" \
        -DTEST_DATA_DIR=\"$(abs_top_srcdir)/tests/data\" \
        -DTEST_ROOTFS=\"$(TEST_ROOTFS)\" \
        -DTEST_STUB_ROOT=\"$(TEST_STUB_ROOT)\"
index 1c8cd1af4821b72f4368ad596508973f502cea75..fbba9f12aadab0feebcf03e965c6771147deb25a 100644 (file)
@@ -35,7 +35,6 @@
 struct testsuite ts;
 
 static int test_run(int i, struct test* t) {
-       struct pakfire_config* config = NULL;
        struct pakfire_ctx* ctx = NULL;
        struct pakfire* p = NULL;
        int r;
@@ -55,23 +54,23 @@ static int test_run(int i, struct test* t) {
        // Log everything to the console
        pakfire_ctx_set_log_callback(t->ctx, pakfire_log_stderr, NULL);
 
-       // Create a pakfire instance (if requested)
-       if (t->flags & TEST_WANTS_PAKFIRE) {
-               // Create a configuration object
-               r = pakfire_config_create(&config);
-               if (r < 0) {
-                       LOG("Could not create configuration object: %s\n", strerror(-r));
-                       goto ERROR;
-               }
+       // Create a configuration object
+       r = pakfire_config_create(&t->config);
+       if (r < 0) {
+               LOG("Could not create configuration object: %s\n", strerror(-r));
+               goto ERROR;
+       }
 
-               // Read the configuration file
-               r = pakfire_config_read_path(config, TEST_SRC_PATH "/pakfire.conf");
-               if (r < 0) {
-                       LOG("Could not read the configuration: %s\n", strerror(-r));
-                       goto ERROR;
-               }
+       // Read the configuration file
+       r = pakfire_config_read_path(t->config, TEST_CONFIG_FILE);
+       if (r < 0) {
+               LOG("Could not read the configuration: %s\n", strerror(-r));
+               goto ERROR;
+       }
 
-               r = pakfire_create(&t->pakfire, t->ctx, config, TEST_STUB_ROOT, NULL, 0);
+       // Create a pakfire instance (if requested)
+       if (t->flags & TEST_WANTS_PAKFIRE) {
+               r = pakfire_create(&t->pakfire, t->ctx, t->config, TEST_STUB_ROOT, NULL, 0);
                if (r < 0) {
                        LOG("ERROR: Could not initialize pakfire: %s\n", strerror(-r));
                        goto ERROR;
@@ -131,8 +130,8 @@ ERROR:
                t->ctx = NULL;
        }
 
-       if (config)
-               pakfire_config_unref(config);
+       if (t->config)
+               pakfire_config_unref(t->config);
 
        return r;
 }
index db69f769d310b359743fa26888f9f8ccf41d0cba..c6bbe71e4d504027f4fb667bb5893eb21bfbd3dc 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <pakfire/config.h>
 #include <pakfire/ctx.h>
 #include <pakfire/httpclient.h>
 #include <pakfire/pakfire.h>
@@ -44,6 +45,9 @@ struct test {
        int (*func)(const struct test* t);
        int flags;
 
+       // Config
+       struct pakfire_config* config;
+
        // Pakfire Context
        struct pakfire_ctx* ctx;