From: Michael Tremer Date: Tue, 21 Sep 2021 15:46:24 +0000 (+0000) Subject: repo: Add test to compose a repository X-Git-Tag: 0.9.28~948 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67849b2408e4daa462ebf3a83206c1afc2babe00;p=pakfire.git repo: Add test to compose a repository Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/repo.c b/tests/libpakfire/repo.c index 56178b62b..8c88a593b 100644 --- a/tests/libpakfire/repo.c +++ b/tests/libpakfire/repo.c @@ -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(); } diff --git a/tests/testsuite.c b/tests/testsuite.c index 3a152a707..8f2cf2260 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -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); +} diff --git a/tests/testsuite.h b/tests/testsuite.h index 2f4cb655e..713e1b5a2 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -135,5 +135,6 @@ int testsuite_run(); // Helper functions FILE* test_mktemp(); +char* test_mkdtemp(); #endif /* PAKFIRE_TESTSUITE_H */