]> git.ipfire.org Git - pakfire.git/commitdiff
packager: Add a test that tries to read a generated package
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Oct 2021 16:23:44 +0000 (16:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Oct 2021 16:23:44 +0000 (16:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/packager.c

index 9a5b7641897aabcae7ac4ddca6440867233a3f77..0e167a8ae1b293d067820f45eacc04a7e52cd1e1 100644 (file)
@@ -64,11 +64,90 @@ FAIL:
        if (repo)
                pakfire_repo_unref(repo);
 
-       return EXIT_SUCCESS;
+       return r;
+}
+
+static int test_compare_metadata(const struct test* t) {
+       struct pakfire_archive* archive = NULL;
+       struct pakfire_package* pkg1 = NULL;
+       struct pakfire_package* pkg2 = NULL;
+       struct pakfire_packager* packager = NULL;
+       char* path = NULL;
+       const char* s = NULL;
+       int r = EXIT_FAILURE;
+
+       // Fetch the dummy repository
+       struct pakfire_repo* repo = pakfire_get_repo(t->pakfire, PAKFIRE_REPO_DUMMY);
+       ASSERT(repo);
+
+       pkg1 = pakfire_package_create(t->pakfire, repo,
+               "test", "1.0-1", "x86_64");
+       ASSERT(pkg1);
+
+       // Set all metadata
+       pakfire_package_set_summary(pkg1, "SUMMARY");
+       pakfire_package_set_description(pkg1, "DESCRIPTION");
+
+       // Create packager
+       ASSERT_SUCCESS(pakfire_packager_create(&packager, pkg1));
+
+       // Write archive
+       FILE* f = test_mktemp(&path);
+       ASSERT(f);
+
+       ASSERT_SUCCESS(pakfire_packager_finish(packager, f));
+
+       printf("Archive written to %s\n", path);
+
+       // Try to open the archive
+       ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
+
+       // Parse package from archive
+       ASSERT_SUCCESS(pakfire_archive_make_package(archive, repo, &pkg2));
+
+       // Compare name
+       s = pakfire_package_get_name(pkg2);
+       ASSERT_STRING_EQUALS(s, "test");
+
+       // Compare evr
+       s = pakfire_package_get_evr(pkg2);
+       ASSERT_STRING_EQUALS(s, "1.0-1");
+
+       // Compare arch
+       s = pakfire_package_get_arch(pkg2);
+       ASSERT_STRING_EQUALS(s, "x86_64");
+
+       // Compare summary
+       s = pakfire_package_get_summary(pkg2);
+       ASSERT_STRING_EQUALS(s, "SUMMARY");
+
+       // Compare description
+       s = pakfire_package_get_description(pkg2);
+       ASSERT_STRING_EQUALS(s, "DESCRIPTION");
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (path)
+               free(path);
+       if (archive)
+               pakfire_archive_unref(archive);
+       if (packager)
+               pakfire_packager_unref(packager);
+       if (pkg1)
+               pakfire_package_unref(pkg1);
+       if (pkg2)
+               pakfire_package_unref(pkg2);
+       if (repo)
+               pakfire_repo_unref(repo);
+
+       return r;
 }
 
 int main(int argc, char** argv) {
        testsuite_add_test(test_create);
+       testsuite_add_test(test_compare_metadata);
 
        return testsuite_run();
 }