From: Michael Tremer Date: Tue, 9 Aug 2022 13:34:36 +0000 (+0000) Subject: tests: Copy command into every test environment X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0cb40254f663f99e7979d3462cff0c3097faa785;p=people%2Fstevee%2Fpakfire.git tests: Copy command into every test environment It looks like we can use this in many cases, so why not copy it by default? Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 39ab5f40..9bc0975a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/tests/testsuite.c b/tests/testsuite.c index cd4efe01..65fca38c 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -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);