]> git.ipfire.org Git - pakfire.git/commitdiff
tests: makefile: Add test for dist
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 May 2022 15:02:32 +0000 (15:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 May 2022 15:02:32 +0000 (15:02 +0000)
This test tries to create a source package for a dummy package. We then
evaluate if we can read correct information back again.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/dist.c
tests/data/packages/dummy/dummy.nm [new file with mode: 0644]
tests/libpakfire/makefile.c

index 77f8cf75e114ad023e51f373154ee5aa7d6d636e..9807957465aa7be7a1df4ba12622fcbd6e86501e 100644 (file)
@@ -789,6 +789,8 @@ EXTRA_DIST += \
        tests/data/compress/data.xz \
        tests/data/compress/data.zst \
        \
+       tests/data/packages/dummy/dummy.nm \
+       \
        tests/data/parser/test-comments.txt \
        tests/data/parser/test-conditionals.txt \
        tests/data/parser/test-declarations.txt \
index a2f686c8cccb6d2505607648155604d79f047c04..03160a8d1f75327942d8abc98fca9bdbe8cc056a 100644 (file)
@@ -181,8 +181,10 @@ int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfir
 
        // Finally, parse the makefile
        r = pakfire_parser_read_file(*parser, path, error);
-       if (r)
+       if (r) {
+               ERROR(pakfire, "Could not read makefile %s: %m\n", path);
                goto ERROR;
+       }
 
        return 0;
 
diff --git a/tests/data/packages/dummy/dummy.nm b/tests/data/packages/dummy/dummy.nm
new file mode 100644 (file)
index 0000000..89e20fe
--- /dev/null
@@ -0,0 +1,27 @@
+###############################################################################
+# IPFire.org    - An Open Source Firewall Solution                            #
+# Copyright (C) - IPFire Development Team <info@ipfire.org>                   #
+###############################################################################
+
+name       = dummy
+version    = 1.0
+release    = 1
+
+groups     = Dummy
+url        = https://www.example.org
+license    = GPLv2+
+summary    = This is a dummy package
+
+description
+       This package is a dummy package and its sole purpose is to have something
+       that we can use for packaging in the test environment.
+       
+       This package purposefully does not download any files.
+end
+
+sources =
+
+# This package has a simple build requirement
+build
+       requires = gcc
+end
index 75dac1c953190125d4cc2526eb8b45ff244183ab..b8218377eaf56dac0c657afd87258a8b486c6f90 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <pakfire/dist.h>
 #include <pakfire/package.h>
 #include <pakfire/parser.h>
 #include <pakfire/repo.h>
@@ -163,10 +164,95 @@ FAIL:
        return r;
 }
 
+/*
+       This test tries to dist() on a dummy package
+*/
+static int test_dist_dummy(const struct test* t) {
+       int r = EXIT_FAILURE;
+
+       struct pakfire_archive* archive = NULL;
+       struct pakfire_package* package = NULL;
+
+       // Create a directory to write packages to
+       char* tmp = test_mkdtemp();
+       ASSERT(tmp);
+
+       char* filename = NULL;
+
+       // Attempt to dist the dummy package
+       ASSERT_SUCCESS(pakfire_dist(t->pakfire,
+               TEST_SRC_PATH "data/packages/dummy/dummy.nm", tmp, &filename));
+
+       // Check if filename is set
+       ASSERT(filename);
+
+       // Check if we can read the archive
+       ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, filename));
+
+       // Extract all package metadata
+       ASSERT_SUCCESS(pakfire_archive_make_package(archive, NULL, &package));
+
+       // Check name
+       const char* name = pakfire_package_get_name(package);
+       ASSERT_STRING_EQUALS(name, "dummy");
+
+       // Check EVR
+       const char* evr = pakfire_package_get_evr(package);
+       ASSERT_STRING_EQUALS(evr, "1.0-1");
+
+       // Check arch
+       const char* arch = pakfire_package_get_arch(package);
+       ASSERT_STRING_EQUALS(arch, "src");
+
+       // Check vendor
+       const char* vendor = pakfire_package_get_vendor(package);
+       ASSERT_STRING_EQUALS(vendor, pakfire_get_distro_vendor(t->pakfire));
+
+       // Check UUID
+       const char* uuid = pakfire_package_get_uuid(package);
+       ASSERT(uuid);
+
+       // Check groups
+       const char* groups = pakfire_package_get_groups(package);
+       ASSERT_STRING_EQUALS(groups, "Dummy");
+
+       // Check URL
+       const char* url = pakfire_package_get_url(package);
+       ASSERT_STRING_EQUALS(url, "https://www.example.org");
+
+       // Check license
+       const char* license = pakfire_package_get_license(package);
+       ASSERT_STRING_EQUALS(license, "GPLv2+");
+
+       // Check summary
+       const char* summary = pakfire_package_get_summary(package);
+       ASSERT_STRING_EQUALS(summary, "This is a dummy package");
+
+       // Check description
+       const char* description = pakfire_package_get_description(package);
+       ASSERT(description);
+
+       // Check size
+       size_t installed_size = pakfire_package_get_installsize(package);
+       ASSERT(installed_size == 0);
+
+       // Everything okay
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (archive)
+               pakfire_archive_unref(archive);
+       if (package)
+               pakfire_package_unref(package);
+
+       return r;
+}
+
 int main(int argc, char** argv) {
        testsuite_add_test(test_macros);
        testsuite_add_test(test_parse);
        testsuite_add_test(test_packages);
+       testsuite_add_test(test_dist_dummy);
 
        return testsuite_run();
 }