From 8b4d2df77b733d4b5ac1d34d8d505c16fdc8eb25 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 19 Oct 2024 09:37:01 +0000 Subject: [PATCH] tests: Try some invalid creations of Pakfire Signed-off-by: Michael Tremer --- src/libpakfire/pakfire.c | 2 +- tests/libpakfire/main.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index ef43e3942..c1f9250a9 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -842,7 +842,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* p->arches.effective = pakfire_arch_is_supported_by_host(arch); if (!p->arches.effective) { CTX_ERROR(p->ctx, "Unsupported architecture: %s\n", arch); - r = -errno; + r = -ENOTSUP; goto ERROR; } diff --git a/tests/libpakfire/main.c b/tests/libpakfire/main.c index 5ac1a7df3..54bb258d0 100644 --- a/tests/libpakfire/main.c +++ b/tests/libpakfire/main.c @@ -34,8 +34,31 @@ FAIL: return EXIT_FAILURE; } +static int test_fail(const struct test* t) { + struct pakfire* pakfire = NULL; + + // Init without anything + ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, NULL, 0) == -EINVAL); + + // Invalid architecture + ASSERT(pakfire_create(&pakfire, t->ctx, NULL, "arch", NULL, 0) == -ENOTSUP); + + // Invalid path (must be absolute) + ASSERT(pakfire_create(&pakfire, t->ctx, "path", NULL, NULL, 0) == -EINVAL); + + // Cannot use snapshots with a path + ASSERT(pakfire_create(&pakfire, t->ctx, PAKFIRE_TMP_DIR "/test", + NULL, NULL, PAKFIRE_USE_SNAPSHOT) == -EINVAL); + + return EXIT_SUCCESS; + +FAIL: + return EXIT_FAILURE; +} + int main(int argc, const char* argv[]) { testsuite_add_test(test_init, TEST_WANTS_PAKFIRE); + testsuite_add_test(test_fail, 0); return testsuite_run(argc, argv); } -- 2.39.5