]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Add test to compose a repository
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Sep 2021 15:46:24 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Sep 2021 15:46:24 +0000 (15:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/repo.c
tests/testsuite.c
tests/testsuite.h

index 56178b62b9add25a22893c2d8ae7a63ac76b658d..8c88a593bb107925a453ef73363400737b0a20bf 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "../testsuite.h"
 
+#define TEST_PKG1_PATH "data/beep-1.3-2.ip3.x86_64.pfm"
+
 static int test_scan(const struct test* t) {
        struct pakfire_repo* repo = NULL;
        char baseurl[1024];
@@ -69,8 +71,37 @@ FAIL:
        return r;
 }
 
+static int test_compose(const struct test* t) {
+       struct pakfire_repo* repo = NULL;
+       int r = EXIT_FAILURE;
+
+       // Create a temporary working directory
+       char* path = test_mkdtemp();
+       ASSERT(path);
+
+       const char* files[] = {
+               TEST_SRC_PATH TEST_PKG1_PATH,
+               NULL,
+       };
+
+       // Compose the repository
+       ASSERT_SUCCESS(
+               pakfire_repo_compose(t->pakfire, path, 0, files)
+       );
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (repo)
+               pakfire_repo_unref(repo);
+
+       return r;
+}
+
 int main(int argc, char** argv) {
        testsuite_add_test(test_scan);
+       testsuite_add_test(test_compose);
 
        return testsuite_run();
 }
index 3a152a70725d72030d8f54de10ff2988b1fafefd..8f2cf2260a258097784360aa8fb1f083687cef64 100644 (file)
@@ -109,3 +109,13 @@ FILE* test_mktemp() {
 
        return fdopen(fd, "w+");
 }
+
+char* test_mkdtemp() {
+       char path[] = "/tmp/.pakfire-test.XXXXXX";
+
+       char* p = mkdtemp(path);
+       if (!p)
+               return NULL;
+
+       return strdup(path);
+}
index 2f4cb655e73188fc9f786b1e993b9c2868a4c71c..713e1b5a285193dffa93a0a01a72394d5ae8b433 100644 (file)
@@ -135,5 +135,6 @@ int testsuite_run();
 
 // Helper functions
 FILE* test_mktemp();
+char* test_mkdtemp();
 
 #endif /* PAKFIRE_TESTSUITE_H */