]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add a test that creates and restores a snapshot
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jul 2022 14:11:53 +0000 (14:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jul 2022 14:11:53 +0000 (14:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
tests/libpakfire/snapshot.c [new file with mode: 0644]

index 343cc95c5b839bc57325fd6ce5365cea48bfa044..4ac99f2b4d810c336a44b1a495ace27ac70739ae 100644 (file)
@@ -29,6 +29,7 @@
 /tests/libpakfire/parser
 /tests/libpakfire/progressbar
 /tests/libpakfire/repo
+/tests/libpakfire/snapshot
 /tests/libpakfire/util
 /tmp
 *.py[co]
index d3c33dc80ee010f1476ddc4076d1de9e99d15e73..b9c4d8fdf7119027cac5496bc31dee38d5fec100 100644 (file)
@@ -381,6 +381,7 @@ check_PROGRAMS += \
        tests/libpakfire/parser \
        tests/libpakfire/progressbar \
        tests/libpakfire/repo \
+       tests/libpakfire/snapshot \
        tests/libpakfire/util
 
 dist_tests_libpakfire_main_SOURCES = \
@@ -577,6 +578,18 @@ tests_libpakfire_repo_CFLAGS = \
 tests_libpakfire_repo_LDADD = \
        $(TESTSUITE_LDADD)
 
+dist_tests_libpakfire_snapshot_SOURCES = \
+       tests/libpakfire/snapshot.c
+
+tests_libpakfire_snapshot_CPPFLAGS = \
+       $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_snapshot_CFLAGS = \
+       $(TESTSUITE_CFLAGS)
+
+tests_libpakfire_snapshot_LDADD = \
+       $(TESTSUITE_LDADD)
+
 dist_tests_libpakfire_util_SOURCES = \
        tests/libpakfire/util.c
 
diff --git a/tests/libpakfire/snapshot.c b/tests/libpakfire/snapshot.c
new file mode 100644 (file)
index 0000000..b3a761d
--- /dev/null
@@ -0,0 +1,64 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <pakfire/pakfire.h>
+#include <pakfire/snapshot.h>
+#include <pakfire/util.h>
+
+#include "../testsuite.h"
+
+#define TEST_PKG1_PATH "data/beep-1.3-2.ip3.x86_64.pfm"
+
+static int test_create_and_restore(const struct test* t) {
+       int r = EXIT_FAILURE;
+
+       // Create a temporary file
+       FILE* f = test_mktemp(NULL);
+       ASSERT(f);
+
+       // Create the snapshot
+       ASSERT_SUCCESS(pakfire_snapshot_create(t->pakfire, f));
+
+       // Determine the size of the snapshot
+       off_t size = ftell(f);
+
+       LOG("Snapshot has a size of %jd bytes\n", size);
+
+       // Rewind the file descriptor to the beginning
+       rewind(f);
+
+       // Perform a restore
+       ASSERT_SUCCESS(pakfire_snapshot_restore(t->pakfire, f));
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (f)
+               fclose(f);
+
+       return r;
+}
+
+int main(int argc, char** argv) {
+       testsuite_add_test(test_create_and_restore);
+
+       return testsuite_run();
+}