]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
downloader: Add a simple test
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Mar 2021 19:13:56 +0000 (19:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Mar 2021 19:13:56 +0000 (19:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
src/libpakfire/downloader.c
src/libpakfire/include/pakfire/downloader.h
tests/libpakfire/downloader.c [new file with mode: 0644]

index a559bbfc732a4378dca2469c5aa0ee8d08e5b9e5..0f5720b63eacfbf77eafad502c41b63e85621405 100644 (file)
@@ -13,6 +13,7 @@
 /tests/libpakfire/arch
 /tests/libpakfire/archive
 /tests/libpakfire/db
+/tests/libpakfire/downloader
 /tests/libpakfire/execute
 /tests/libpakfire/key
 /tests/libpakfire/main
index 801fa517f32f8c997f37e061431677c2b914187d..dfb4368f06aa9c3fee96f00e0de5e77d76f3b2c8 100644 (file)
@@ -367,6 +367,7 @@ check_PROGRAMS += \
        tests/libpakfire/arch \
        tests/libpakfire/archive \
        tests/libpakfire/db \
+       tests/libpakfire/downloader \
        tests/libpakfire/execute \
        tests/libpakfire/key \
        tests/libpakfire/makefile \
@@ -416,6 +417,21 @@ tests_libpakfire_db_LDADD = \
        $(TESTSUITE_LDADD) \
        $(PAKFIRE_LIBS)
 
+dist_tests_libpakfire_downloader_SOURCES = \
+       tests/libpakfire/downloader.c \
+       src/libpakfire/downloader.c \
+       src/libpakfire/util.c
+
+tests_libpakfire_downloader_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS) \
+       -DPAKFIRE_PRIVATE
+
+tests_libpakfire_downloader_LDADD = \
+       $(TESTSUITE_LDADD) \
+       $(CURL_LIBS) \
+       $(PAKFIRE_LIBS) \
+       $(UUID_LIBS)
+
 tests_libpakfire_execute_SOURCES = \
        tests/libpakfire/execute.c
 
@@ -631,13 +647,13 @@ tests_libtestsuite_la_SOURCES = \
        tests/testsuite.h
 
 tests_libtestsuite_la_CPPFLAGS = \
-       $(TESTSUITE_CPPFLAGS) \
-       -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\" \
-       -DTEST_ROOTFS=\"$(TEST_ROOTFS)\"
+       $(TESTSUITE_CPPFLAGS)
 
 TESTSUITE_CPPFLAGS = \
        $(AM_CPPFLAGS) \
-       $(PAKFIRE_CPPFLAGS)
+       $(PAKFIRE_CPPFLAGS) \
+       -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\" \
+       -DTEST_ROOTFS=\"$(TEST_ROOTFS)\"
 
 TESTSUITE_LDADD = \
        tests/libtestsuite.la
index 7e455163e47dbb9d5275bf5b6dce6c463aebb091..f367a93920fdf8b9787f9e555961d3483d30f6b5 100644 (file)
@@ -334,6 +334,21 @@ static int pakfire_transfer_done(struct pakfire_downloader* downloader,
        return 0;
 }
 
+int pakfire_downloader_retrieve(struct pakfire_downloader* downloader,
+               const char* url, const char* path) {
+       // Do not run this when there are transfers pending
+       if (!TAILQ_EMPTY(&downloader->transfers))
+               return EBUSY;
+
+       // Add the transfer
+       int r = pakfire_downloader_add(downloader, url, path);
+       if (r)
+               return r;
+
+       // Run it
+       return pakfire_downloader_run(downloader);
+}
+
 int pakfire_downloader_add(struct pakfire_downloader* downloader,
                const char* url, const char* path) {
        DEBUG(downloader->pakfire, "Adding download of %s\n", url);
index 75116dabec1b2195e79b2b45fa526978b33437f5..6ad4e50974a60fce989466c548dea48c4123eda8 100644 (file)
@@ -38,6 +38,8 @@ void pakfire_downloader_set_baseurl(struct pakfire_downloader* downloader, const
 int pakfire_downloader_add_mirror(struct pakfire_downloader* downloader,
        const char* url, unsigned int priority);
 
+int pakfire_downloader_retrieve(struct pakfire_downloader* downloader,
+               const char* url, const char* path);
 int pakfire_downloader_add(struct pakfire_downloader* downloader,
        const char* url, const char* path);
 
diff --git a/tests/libpakfire/downloader.c b/tests/libpakfire/downloader.c
new file mode 100644 (file)
index 0000000..745570c
--- /dev/null
@@ -0,0 +1,50 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <pakfire/downloader.h>
+
+#include "../testsuite.h"
+
+#define DOWNLOAD_URL "file://" ABS_TOP_SRCDIR "/tests/data/beep-1.3-2.ip3.x86_64.pfm"
+
+#define DOWNLOAD_PATH TEST_ROOTFS "/downloaded.file"
+
+static int test_simple(const struct test* t) {
+       struct pakfire_downloader* d;
+
+       // Create downloader
+       int r = pakfire_downloader_create(&d, t->pakfire);
+       ASSERT(r == 0);
+
+       // Retrieve a file
+       r = pakfire_downloader_retrieve(d, DOWNLOAD_URL, DOWNLOAD_PATH);
+       ASSERT(r == 0);
+
+       // Cleanup
+       pakfire_downloader_unref(d);
+
+       return EXIT_SUCCESS;
+}
+
+int main(int argc, char** argv) {
+       testsuite_add_test(test_simple);
+
+       return testsuite_run();
+}