]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
downloader: Add test using mirrors
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Apr 2021 16:15:10 +0000 (16:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Apr 2021 16:15:10 +0000 (16:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/downloader.c
tests/testsuite.h

index ccf80d6cc0aac020ded58613ce20322851d12523..6736fbdfd1afc30b9e12b8dd1a6fcec4c934b6b8 100644 (file)
@@ -66,9 +66,40 @@ static int test_retrieve_with_pending_transfers(const struct test* t) {
        return EXIT_SUCCESS;
 }
 
+static int test_retrieve_with_mirrors(const struct test* t) {
+       struct pakfire_downloader* d;
+       struct pakfire_mirrorlist* m;
+
+       // Create downloader
+       int r = pakfire_downloader_create(&d, t->pakfire);
+       ASSERT(r == 0);
+
+       // Create mirrorlist
+       ASSERT_SUCCESS(pakfire_mirrorlist_create(&m, t->pakfire));
+
+       // Add a couple of mirrors
+       ASSERT_SUCCESS(pakfire_mirrorlist_add_mirror(m, "file://" ABS_TOP_SRCDIR "/tests/data/mirror-1"));
+       ASSERT_SUCCESS(pakfire_mirrorlist_add_mirror(m, "file://" ABS_TOP_SRCDIR "/tests/data/mirror-2"));
+       ASSERT_SUCCESS(pakfire_mirrorlist_add_mirror(m, "file://" ABS_TOP_SRCDIR "/tests/data/mirror-3"));
+       ASSERT_SUCCESS(pakfire_mirrorlist_add_mirror(m, "file://" ABS_TOP_SRCDIR "/tests/data"));
+
+       // Retrieve a file which doesn't exist
+       //ASSERT_FAILURE(pakfire_downloader_retrieve(d, m, "doesnt-exist.pfm", DOWNLOAD_PATH));
+
+       // Retrieve a file which exists
+       ASSERT_SUCCESS(pakfire_downloader_retrieve(d, m, "beep-1.3-2.ip3.x86_64.pfm", DOWNLOAD_PATH));
+
+       // Cleanup
+       ASSERT_NULL(pakfire_mirrorlist_unref(m));
+       ASSERT_NULL(pakfire_downloader_unref(d));
+
+       return 0;
+}
+
 int main(int argc, char** argv) {
        testsuite_add_test(test_simple);
        testsuite_add_test(test_retrieve_with_pending_transfers);
+       testsuite_add_test(test_retrieve_with_mirrors);
 
        return testsuite_run();
 }
index 0549d49f2c55a558e8c821b5bce3bfbe0f78b82c..0b025042ea1963583002d3445a1877d488dd021b 100644 (file)
@@ -81,6 +81,15 @@ int testsuite_run();
                } \
        } while (0)
 
+#define ASSERT_FAILURE(expr) \
+       do { \
+               if ((expr) > 0) { \
+                       LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
+                               __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+                       return EXIT_FAILURE; \
+               } \
+       } while (0)
+
 #define ASSERT_ERRNO(expr, e) \
        do { \
                if (!(expr)) { \