From: Martin Vidner Date: Fri, 15 Nov 2019 09:40:12 +0000 (+0100) Subject: Integration test X-Git-Tag: v0.8.6~4^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c23552d8c1745ed99c161469c7e0664fa60c1998;p=thirdparty%2Fsnapper.git Integration test --- diff --git a/testsuite-real/CAUTION b/testsuite-real/CAUTION index c52ea407..ac0d3dc2 100644 --- a/testsuite-real/CAUTION +++ b/testsuite-real/CAUTION @@ -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 index ea8f542b..00000000 --- a/testsuite-real/README +++ /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 index 00000000..7916bbb9 --- /dev/null +++ b/testsuite-real/README.md @@ -0,0 +1 @@ +CAUTION \ No newline at end of file diff --git a/testsuite-real/run-all b/testsuite-real/run-all index c7366afb..70afdfbd 100755 --- a/testsuite-real/run-all +++ b/testsuite-real/run-all @@ -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 index 00000000..d27119f8 --- /dev/null +++ b/testsuite-real/setup-and-run-all @@ -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