From: Michael Tremer Date: Sun, 5 Jan 2025 14:00:17 +0000 (+0000) Subject: tests: Fix them after the recent changes X-Git-Tag: 0.9.30~531 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d99ffa50257e773fa9ed303a44816386297826f;p=pakfire.git tests: Fix them after the recent changes Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/config.c b/src/pakfire/config.c index b3547a70f..f6d0256e6 100644 --- a/src/pakfire/config.c +++ b/src/pakfire/config.c @@ -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; diff --git a/src/pakfire/config.h b/src/pakfire/config.h index 145c085d5..81d7ffadd 100644 --- a/src/pakfire/config.h +++ b/src/pakfire/config.h @@ -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); diff --git a/tests/libpakfire/build.c b/tests/libpakfire/build.c index 7d656202d..0791f7264 100644 --- a/tests/libpakfire/build.c +++ b/tests/libpakfire/build.c @@ -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); } diff --git a/tests/libpakfire/main.c b/tests/libpakfire/main.c index 54bb258d0..f5b9c4fd4 100644 --- a/tests/libpakfire/main.c +++ b/tests/libpakfire/main.c @@ -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; diff --git a/tests/testsuite.c b/tests/testsuite.c index dfb045dca..1c8cd1af4 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -24,6 +24,7 @@ #include "testsuite.h" +#include #include #include #include @@ -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; }