]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Fix them after the recent changes
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Jan 2025 14:00:17 +0000 (14:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Jan 2025 14:00:17 +0000 (14:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/config.c
src/pakfire/config.h
tests/libpakfire/build.c
tests/libpakfire/main.c
tests/testsuite.c

index b3547a70f3e3fab65e111625e455c827d1db46de..f6d0256e605ac66adfc88e40fe288ca39dcd9a06 100644 (file)
@@ -517,6 +517,24 @@ ERROR:
        return r;
 }
 
+int pakfire_config_read_path(struct pakfire_config* config, const char* path) {
+       FILE* f = NULL;
+       int r;
+
+       // Open the file
+       f = fopen(path, "r");
+       if (!f)
+               return -errno;
+
+       // Read the configuration
+       r = pakfire_config_read(config, f);
+
+       // Close the file
+       fclose(f);
+
+       return r;
+}
+
 int pakfire_config_parse(struct pakfire_config* config, const char* s, ssize_t length) {
        FILE* f = NULL;
        int r;
index 145c085d5d767707bf4ba7a54319ff5b38fc20cf..81d7ffadd12dde0b4707afc110f6fb454d05aa7b 100644 (file)
@@ -55,6 +55,7 @@ int pakfire_config_walk_sections(struct pakfire_config* config,
 int pakfire_config_has_section(struct pakfire_config* config, const char* section);
 
 int pakfire_config_read(struct pakfire_config* config, FILE* f);
+int pakfire_config_read_path(struct pakfire_config* config, const char* path);
 int pakfire_config_parse(struct pakfire_config* config, const char* s, ssize_t length);
 
 int pakfire_config_dump(struct pakfire_config* config, FILE* f);
index 7d656202dc5ad9c04d19b7508d105e95d07c483c..0791f7264f4a1cc289941157e74f77242ba871db 100644 (file)
@@ -28,7 +28,7 @@ static int test_create_and_free(const struct test* t) {
        struct pakfire_build* build = NULL;
 
        // Create a new build
-       ASSERT_SUCCESS(pakfire_build_create(&build, t->pakfire, NULL, 0));
+       ASSERT_SUCCESS(pakfire_build_create(&build, t->ctx, NULL, NULL, 0));
 
        // Check if build actually got allocated
        ASSERT(build);
@@ -46,10 +46,10 @@ static int test_create_with_invalid_ids(const struct test* t) {
        struct pakfire_build* build = NULL;
 
        // Try to create a build with an invalid UUID
-       ASSERT(pakfire_build_create(&build, t->pakfire, "ABC", 0) == -EINVAL);
+       ASSERT(pakfire_build_create(&build, t->ctx, NULL, "ABC", 0) == -EINVAL);
 
        // Try to create a build with an empty UUID
-       ASSERT(pakfire_build_create(&build, t->pakfire, "", 0) == -EINVAL);
+       ASSERT(pakfire_build_create(&build, t->ctx, NULL, "", 0) == -EINVAL);
 
        return EXIT_SUCCESS;
 
@@ -58,8 +58,8 @@ FAIL:
 }
 
 int main(int argc, const char* argv[]) {
-       testsuite_add_test(test_create_and_free, TEST_WANTS_PAKFIRE);
-       testsuite_add_test(test_create_with_invalid_ids, TEST_WANTS_PAKFIRE);
+       testsuite_add_test(test_create_and_free, 0);
+       testsuite_add_test(test_create_with_invalid_ids, 0);
 
        return testsuite_run(argc, argv);
 }
index 54bb258d047fa214cae2f6b7f07c315d5d8db06b..f5b9c4fd47568d352798ca88ecaa36fd23c570f7 100644 (file)
@@ -41,14 +41,14 @@ static int test_fail(const struct test* t) {
        ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, NULL, 0) == -EINVAL);
 
        // Invalid architecture
-       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, "arch", NULL, 0) == -ENOTSUP);
+       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, "arch", 0) == -ENOTSUP);
 
        // Invalid path (must be absolute)
-       ASSERT(pakfire_create(&pakfire, t->ctx, "path", NULL, NULL, 0) == -EINVAL);
+       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, "path", NULL, 0) == -EINVAL);
 
        // Cannot use snapshots with a path
-       ASSERT(pakfire_create(&pakfire, t->ctx, PAKFIRE_TMP_DIR "/test",
-               NULL, NULL, PAKFIRE_USE_SNAPSHOT) == -EINVAL);
+       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, PAKFIRE_TMP_DIR "/test",
+               NULL, PAKFIRE_USE_SNAPSHOT) == -EINVAL);
 
        return EXIT_SUCCESS;
 
index dfb045dca30cd967febe447981a598debdb26581..1c8cd1af4821b72f4368ad596508973f502cea75 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "testsuite.h"
 
+#include <pakfire/config.h>
 #include <pakfire/logging.h>
 #include <pakfire/mount.h>
 #include <pakfire/pakfire.h>
@@ -34,9 +35,9 @@
 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;
-       FILE* c = NULL;
        int r;
 
        LOG("running %s\n", t->name);
@@ -54,17 +55,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);
 
-       // Open the configuration file
-       c = fopen(TEST_SRC_PATH "/pakfire.conf", "r");
-       if (!c) {
-               LOG("Could not open configuration file: %m\n");
-               r = 1;
-               goto ERROR;
-       }
-
        // Create a pakfire instance (if requested)
        if (t->flags & TEST_WANTS_PAKFIRE) {
-               r = pakfire_create(&t->pakfire, t->ctx, TEST_STUB_ROOT, NULL, c, 0);
+               // Create a configuration object
+               r = pakfire_config_create(&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;
+               }
+
+               r = pakfire_create(&t->pakfire, t->ctx, config, TEST_STUB_ROOT, NULL, 0);
                if (r < 0) {
                        LOG("ERROR: Could not initialize pakfire: %s\n", strerror(-r));
                        goto ERROR;
@@ -124,9 +131,8 @@ ERROR:
                t->ctx = NULL;
        }
 
-       // Close the configuration file
-       if (c)
-               fclose(c);
+       if (config)
+               pakfire_config_unref(config);
 
        return r;
 }