From: Michael Tremer Date: Thu, 15 Apr 2021 16:15:10 +0000 (+0000) Subject: downloader: Add test using mirrors X-Git-Tag: 0.9.28~1285^2~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49f17efcc82f50abb4aa41b47072af4eb36c35d1;p=pakfire.git downloader: Add test using mirrors Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/downloader.c b/tests/libpakfire/downloader.c index ccf80d6cc..6736fbdfd 100644 --- a/tests/libpakfire/downloader.c +++ b/tests/libpakfire/downloader.c @@ -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(); } diff --git a/tests/testsuite.h b/tests/testsuite.h index 0549d49f2..0b025042e 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -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)) { \