]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Test writing/reading the SOLV database
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Sep 2021 15:28:46 +0000 (15:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Sep 2021 15:28:46 +0000 (15:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/repo.c
tests/testsuite.c

index cbf06ae1ce6ac08af75f07fd7b8e925e299204d3..56178b62b9add25a22893c2d8ae7a63ac76b658d 100644 (file)
@@ -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;
 }
index 20594be8c36ee78c241a0bb142c854a6ad991f5a..3a152a70725d72030d8f54de10ff2988b1fafefd 100644 (file)
@@ -107,5 +107,5 @@ FILE* test_mktemp() {
        if (fd < 0)
                return NULL;
 
-       return fdopen(fd, "w");
+       return fdopen(fd, "w+");
 }