]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Try some invalid creations of Pakfire
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 09:37:01 +0000 (09:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 09:37:01 +0000 (09:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c
tests/libpakfire/main.c

index ef43e394287f620897c994f16fe698080fdfc72d..c1f9250a9fa897c3188d9a8a297654f75d1a10cf 100644 (file)
@@ -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;
        }
 
index 5ac1a7df36c5506fb90990a48d8083b7d29779ae..54bb258d047fa214cae2f6b7f07c315d5d8db06b 100644 (file)
@@ -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);
 }