]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Integration test
authorMartin Vidner <mvidner@suse.cz>
Fri, 15 Nov 2019 09:40:12 +0000 (10:40 +0100)
committerMartin Vidner <mvidner@suse.cz>
Tue, 26 Nov 2019 13:40:01 +0000 (14:40 +0100)
testsuite-real/CAUTION
testsuite-real/README [deleted file]
testsuite-real/README.md [new symlink]
testsuite-real/run-all
testsuite-real/setup-and-run-all [new file with mode: 0755]

index c52ea407141726995ca5e9605b74e41252b524ab..ac0d3dc22d1fbafcbfd50c1a48b880b7c61c8319 100644 (file)
@@ -1,6 +1,18 @@
-
 CAUTION
 -------
 
-The programs here destroy data on your disks!
+RUN THESE TESTS IN A SCRATCH MACHINE.
+
+The tests in this directory only work when run as the root user.
+
+They operate
+- on a scratch BTRFS filesystem (`/testsuite`)
+- created in a loopback-mounted file (`/testsuite.img`),
+- using a scratch Snapper configuration (`testsuite`).
+
+However bugs do happen so it is recommended that you
+run these tests in a scratch machine. A bug may cause
+LOSS OR CORRUPTION OF YOUR OWN BTRFS SNAPSHOTS AND DATA.
 
+See `setup-and-run-all` for the scratch setup and `run-all` for the actual
+test set.
diff --git a/testsuite-real/README b/testsuite-real/README
deleted file mode 100644 (file)
index ea8f542..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-
-To run testsuite:
-
-- read the CAUTION file
-
-- create subvolume /testsuite
-
-  btrfs subvolume create /testsuite
-
-- create snapper config for testsuite
-
-  snapper --config=testsuite create-config /testsuite
-
-- run test
-
-  ./run-all
-
diff --git a/testsuite-real/README.md b/testsuite-real/README.md
new file mode 120000 (symlink)
index 0000000..7916bbb
--- /dev/null
@@ -0,0 +1 @@
+CAUTION
\ No newline at end of file
index c7366afbfd2ba3357f99e16436afddff9552443c..70afdfbd94d5315c8c1e80a3423dd218472417f6 100755 (executable)
@@ -1,5 +1,10 @@
 #!/bin/bash
 
+if [ "$(id -u)" != "0" ]; then
+   echo "These tests only work when run as root." >&2
+   echo "Yes. See also the CAUTION file." >&2
+   exit 1
+fi
 
 function run()
 {
diff --git a/testsuite-real/setup-and-run-all b/testsuite-real/setup-and-run-all
new file mode 100755 (executable)
index 0000000..d27119f
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/bash
+set -eu
+set -x
+if [ "$(id -u)" != "0" ]; then
+    set +x
+    echo "These tests only work when run as root." >&2
+    echo "Yes. See also the CAUTION file." >&2
+    exit 1
+fi
+
+CFG=testsuite
+MNT=/"$CFG"
+#CFG=scratch2
+#MNT=~/"$CFG"-btrfs
+IMG="$MNT".img
+
+forget_config() {
+    sed -i -e "/^SNAPPER_CONFIGS=/s/\b${CFG}\b//" /etc/sysconfig/snapper
+}
+
+setup() {
+    if [ -f "$IMG" ]; then
+        set +x
+        echo >&2 "The image '$IMG' already exists, aborting setup."
+        echo >&2 "Probably a previous test run failed."
+        echo >&2 "After you inspect the artifacts, run '$0 teardown' to clean up."
+        exit 1
+    fi
+    dd if=/dev/zero of="$IMG" bs=1M count=110
+    LOOP=$(losetup --find)
+    losetup "$LOOP" "$IMG"
+    mkfs.btrfs "$LOOP"
+    mkdir -p "$MNT"
+    mount "$IMG" "$MNT"
+    forget_config
+    snapper --no-dbus --config="$CFG" create-config "$MNT"
+}
+
+main() {
+    # read -p "Enter to CONTINUE, Ctrl-C to exit:"
+    ./run-all
+}
+
+teardown() {
+    snapper --no-dbus --config="$CFG" delete-config || forget_config
+    if grep "$MNT" /proc/mounts >/dev/null; then
+        umount "$MNT"
+    fi
+    if [ -d "$MNT" ]; then
+        rmdir "$MNT"
+    fi
+    # mapfile is better than VAR=($(cmd))
+    # https://github.com/koalaman/shellcheck/wiki/SC2207
+    mapfile -t LOOPS < <(losetup --associated "$IMG" | cut -f1 -d:)
+    if [ ${#LOOPS[@]} != 0 ]; then
+        losetup --detach "${LOOPS[@]}"
+    fi
+    rm -f "$IMG"
+}
+
+all() {
+    setup
+    main
+    teardown
+}
+
+ACTION=${1-all}
+$ACTION