From: Michael Tremer Date: Tue, 21 Sep 2021 15:28:46 +0000 (+0000) Subject: repo: Test writing/reading the SOLV database X-Git-Tag: 0.9.28~949 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8c8f799c224d0a245045868d81f41a01268ff71;p=pakfire.git repo: Test writing/reading the SOLV database Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/repo.c b/tests/libpakfire/repo.c index cbf06ae1c..56178b62b 100644 --- a/tests/libpakfire/repo.c +++ b/tests/libpakfire/repo.c @@ -27,25 +27,44 @@ static int test_scan(const struct test* t) { struct pakfire_repo* repo = NULL; char baseurl[1024]; int r = EXIT_FAILURE; + FILE* f = NULL; pakfire_string_format(baseurl, "file://%s/data", TEST_SRC_PATH); ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test")); ASSERT(repo); + // Set the base URL (where to scan for files) ASSERT_SUCCESS(pakfire_repo_set_baseurl(repo, baseurl)); + // Scan for all files in this directory ASSERT_SUCCESS(pakfire_repo_scan(repo, 0)); // There should be one package in this repository now ASSERT(pakfire_repo_count(repo) == 1); + // Allocate a temporary file + f = test_mktemp(); + ASSERT(f); + + // Write SOLV database + ASSERT_SUCCESS(pakfire_repo_write_solv(repo, f, 0)); + rewind(f); + + // Read SOLV database again + ASSERT_SUCCESS(pakfire_repo_read_solv(repo, f, 0)); + + // There should still be exactly one package be in this repository + ASSERT(pakfire_repo_count(repo) == 1); + // Everything passed r = EXIT_SUCCESS; FAIL: if (repo) pakfire_repo_unref(repo); + if (f) + fclose(f); return r; } diff --git a/tests/testsuite.c b/tests/testsuite.c index 20594be8c..3a152a707 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -107,5 +107,5 @@ FILE* test_mktemp() { if (fd < 0) return NULL; - return fdopen(fd, "w"); + return fdopen(fd, "w+"); }