]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Copy command into every test environment
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 13:34:36 +0000 (13:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Aug 2022 13:34:36 +0000 (13:34 +0000)
It looks like we can use this in many cases, so why not copy it by
default?

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/testsuite.c

index 39ab5f4059d2d1721b942e9ac2be85cbf6cd3dac..9bc0975af4ed868dd4ea375dcb190893142b4405 100644 (file)
@@ -803,6 +803,7 @@ TESTSUITE_CPPFLAGS = \
        $(PAKFIRE_CPPFLAGS) \
        -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\" \
        -DTEST_ROOTFS=\"$(TEST_ROOTFS)\" \
+       -DTEST_STUB_COMMAND=\"$(abs_top_builddir)/tests/stub/root/command\" \
        -DTEST_STUB_ROOT=\"$(TEST_STUB_ROOT)\" \
        -DPAKFIRE_PRIVATE
 
index cd4efe01efd800d3d6cdf54f79a70372822cca10..65fca38c700162db4c340a743fcef24c151f53be 100644 (file)
@@ -33,6 +33,8 @@
 struct testsuite ts;
 
 static int test_run(int i, struct test* t) {
+       struct pakfire* p = NULL;
+
        char root[PATH_MAX] = TEST_ROOTFS "/pakfire-test-XXXXXX";
        int r;
 
@@ -50,15 +52,24 @@ static int test_run(int i, struct test* t) {
                0, LOG_DEBUG, pakfire_log_stderr, NULL);
        if (r) {
                LOG("ERROR: Could not initialize pakfire: %m\n");
-               exit(1);
+               goto ERROR;
+       }
+
+       // Copy command into environment
+       r = pakfire_copy_in(t->pakfire, TEST_STUB_COMMAND, "/command");
+       if (r) {
+               LOG("ERROR: Could not copy command: %m\n");
+               goto ERROR;
        }
 
+       // Run test
        r = t->func(t);
        if (r)
                LOG("Test failed with error code: %d\n", r);
 
+ERROR:
        // Release pakfire
-       struct pakfire* p = pakfire_unref(t->pakfire);
+       p = pakfire_unref(t->pakfire);
 
        // Check if Pakfire was actually released
        if (p) {
@@ -66,6 +77,9 @@ static int test_run(int i, struct test* t) {
                return 1;
        }
 
+       // Reset pointer (just in case)
+       t->pakfire = NULL;
+
        // Cleanup root
        pakfire_rmtree(root, 0);