From 7b026358b9de5f0025f3a0c68a287cf1c4b3c960 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Sun, 28 Apr 2024 15:31:42 +0100 Subject: [PATCH] tests/env.sh: Expose TEST_ID variable to tests Its value is a random identifier unique to the current run of the current test. Signed-off-by: Alberto Faria --- tests/env.sh | 1 + tests/t/bootc-disk-size.sh | 10 +++++----- tests/t/cloud-init.sh | 8 ++++---- tests/t/emulated.sh | 4 ++-- tests/t/hostname.sh | 16 ++++++++-------- tests/t/ignition.sh | 6 +++--- tests/t/mount.sh | 14 +++++++------- tests/t/persistent.sh | 8 ++++---- tests/t/publish.sh | 12 ++++++------ tests/t/random-ssh-key-pair.sh | 8 ++++---- tests/t/stop-start.sh | 10 +++++----- 11 files changed, 49 insertions(+), 48 deletions(-) diff --git a/tests/env.sh b/tests/env.sh index 7400856..2172101 100755 --- a/tests/env.sh +++ b/tests/env.sh @@ -392,6 +392,7 @@ run) } TEMP_DIR=~/$label.temp UTIL_DIR=~/$label.util + TEST_ID=$label ENGINE=$engine export RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=1 $( cat "$t" )\ diff --git a/tests/t/bootc-disk-size.sh b/tests/t/bootc-disk-size.sh index 64fa602..6d31461 100644 --- a/tests/t/bootc-disk-size.sh +++ b/tests/t/bootc-disk-size.sh @@ -4,13 +4,13 @@ image="${TEST_IMAGES[fedora-bootc]}" user="${TEST_IMAGES_DEFAULT_USER[fedora-bootc]}" __run() { - __engine run --detach --name bootc-disk-size "$image" --bootc-disk-size "$1" + __engine run --detach --name "$TEST_ID" "$image" --bootc-disk-size "$1" } __run 1M -! __engine exec bootc-disk-size --as "$user" -__engine rm --force bootc-disk-size +! __engine exec "$TEST_ID" --as "$user" +__engine rm --force "$TEST_ID" __run 4G -__engine exec bootc-disk-size --as "$user" -__engine rm --force bootc-disk-size +__engine exec "$TEST_ID" --as "$user" +__engine rm --force "$TEST_ID" diff --git a/tests/t/cloud-init.sh b/tests/t/cloud-init.sh index 5ac77e1..69575d2 100644 --- a/tests/t/cloud-init.sh +++ b/tests/t/cloud-init.sh @@ -19,18 +19,18 @@ EOF __engine run \ --rm --detach \ - --name cloud-init \ + --name "$TEST_ID" \ "$image" \ --cloud-init "$TEMP_DIR" __test() { - __engine exec cloud-init --as "$user" "cmp $home/file <<< hello" + __engine exec "$TEST_ID" --as "$user" "cmp $home/file <<< hello" } __test - __engine restart cloud-init + __engine restart "$TEST_ID" __test - __engine stop cloud-init + __engine stop "$TEST_ID" done diff --git a/tests/t/emulated.sh b/tests/t/emulated.sh index 0b6675a..7cffb4b 100644 --- a/tests/t/emulated.sh +++ b/tests/t/emulated.sh @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-or-later -__engine run --detach --name emulated "${TEST_IMAGES[fedora]}" --emulated -__engine exec emulated --as fedora +__engine run --detach --name "$TEST_ID" "${TEST_IMAGES[fedora]}" --emulated +__engine exec "$TEST_ID" --as fedora diff --git a/tests/t/hostname.sh b/tests/t/hostname.sh index c185f76..9879af2 100644 --- a/tests/t/hostname.sh +++ b/tests/t/hostname.sh @@ -7,36 +7,36 @@ for os in "${!TEST_IMAGES[@]}"; do # default hostname - id=$( __engine run --rm --detach --name "hostname-$os-default" "$image" ) + id=$( __engine run --rm --detach --name "$TEST_ID-$os-default" "$image" ) __test() { - __engine exec "hostname-$os-default" --as "$user" \ + __engine exec "$TEST_ID-$os-default" --as "$user" \ "set -x && [[ \$( hostname ) == ${id::12} ]]" } __test - __engine restart "hostname-$os-default" + __engine restart "$TEST_ID-$os-default" __test - __engine stop --time 0 "hostname-$os-default" + __engine stop --time 0 "$TEST_ID-$os-default" # custom hostname __engine run \ --rm --detach \ - --name "hostname-$os-custom" \ + --name "$TEST_ID-$os-custom" \ --hostname my-test-vm \ "$image" __test() { - __engine exec "hostname-$os-custom" --as "$user" \ + __engine exec "$TEST_ID-$os-custom" --as "$user" \ "set -x && [[ \$( hostname ) == my-test-vm ]]" } __test - __engine restart "hostname-$os-custom" + __engine restart "$TEST_ID-$os-custom" __test - __engine stop --time 0 "hostname-$os-custom" + __engine stop --time 0 "$TEST_ID-$os-custom" done diff --git a/tests/t/ignition.sh b/tests/t/ignition.sh index d2cab70..e2cfb9c 100644 --- a/tests/t/ignition.sh +++ b/tests/t/ignition.sh @@ -26,14 +26,14 @@ EOF __engine run \ --rm --detach \ - --name ignition \ + --name "$TEST_ID" \ "$image" \ --ignition "$TEMP_DIR/config.ign" __test() { - __engine exec ignition --as "$user" "cmp $home/file <<< hello" + __engine exec "$TEST_ID" --as "$user" "cmp $home/file <<< hello" } __test -__engine restart ignition +__engine restart "$TEST_ID" __test diff --git a/tests/t/mount.sh b/tests/t/mount.sh index 4be1085..726b596 100644 --- a/tests/t/mount.sh +++ b/tests/t/mount.sh @@ -10,37 +10,37 @@ for os in "${!TEST_IMAGES[@]}"; do __engine run \ --rm --detach \ - --name "mount-$os" \ + --name "$TEST_ID-$os" \ --volume "$TEMP_DIR/file:$home/file:z" \ --volume "$TEMP_DIR:$home/dir:z" \ --mount "type=tmpfs,dst=$home/tmp" \ "$image" __test() { - __engine exec "mount-$os" --as "$user" + __engine exec "$TEST_ID-$os" --as "$user" - __engine exec "mount-$os" --as "$user" " + __engine exec "$TEST_ID-$os" --as "$user" " set -e [[ -b $home/file ]] sudo cmp -n 6 $home/file <<< hello " - __engine exec "mount-$os" --as "$user" " + __engine exec "$TEST_ID-$os" --as "$user" " set -e mount -l | grep '^virtiofs-0 on $home/dir type virtiofs' [[ -d $home/dir ]] sudo cmp $home/dir/file <<< hello " - __engine exec "mount-$os" --as "$user" " + __engine exec "$TEST_ID-$os" --as "$user" " mount -l | grep '^tmpfs on $home/tmp type tmpfs' " } __test - __engine restart "mount-$os" + __engine restart "$TEST_ID-$os" __test - __engine stop --time 0 "mount-$os" + __engine stop --time 0 "$TEST_ID-$os" done diff --git a/tests/t/persistent.sh b/tests/t/persistent.sh index 0f8c266..e850031 100644 --- a/tests/t/persistent.sh +++ b/tests/t/persistent.sh @@ -9,14 +9,14 @@ fi # Usage: __run [] __run() { - __engine run --rm --detach --name persistent "${@:2}" --rootfs "$TEMP_DIR" "$1" + __engine run --rm --detach --name "$TEST_ID" "${@:2}" --rootfs "$TEMP_DIR" "$1" } # Usage: __test __test() { id=$( __run "$1" ) - __engine exec persistent --as fedora "$2" - __engine stop persistent + __engine exec "$TEST_ID" --as fedora "$2" + __engine stop "$TEST_ID" if [[ "$ENGINE" != rootful-podman ]]; then # ensure user that invoked `engine run` can delete crun-vm state @@ -34,4 +34,4 @@ __test "" '[[ -e i-was-here ]]' ! RUST_LIB_BACKTRACE=0 __run --persistent --read-only __run "" --read-only -__engine exec persistent --as fedora +__engine exec "$TEST_ID" --as fedora diff --git a/tests/t/publish.sh b/tests/t/publish.sh index 45ef70a..07213d9 100644 --- a/tests/t/publish.sh +++ b/tests/t/publish.sh @@ -1,22 +1,22 @@ # SPDX-License-Identifier: GPL-2.0-or-later -trap '__engine stop publish' EXIT +trap '__engine stop "$TEST_ID"' EXIT for os in fedora fedora-bootc; do image="${TEST_IMAGES[$os]}" user="${TEST_IMAGES_DEFAULT_USER[$os]}" - __engine run --rm --detach --name publish --publish 127.0.0.1::8000 "$image" + __engine run --rm --detach --name "$TEST_ID" --publish 127.0.0.1::8000 "$image" - endpoint=$( __engine port publish | tee /dev/stderr | cut -d' ' -f3 ) + endpoint=$( __engine port "$TEST_ID" | tee /dev/stderr | cut -d' ' -f3 ) - __engine exec publish --as "$user" + __engine exec "$TEST_ID" --as "$user" __log 'Ensuring curl fails...' ! curl "$endpoint" 2>/dev/null - __engine exec publish --as "$user" python -m http.server & + __engine exec "$TEST_ID" --as "$user" python -m http.server & __log 'Ensuring curl succeeds...' @@ -28,6 +28,6 @@ for os in fedora fedora-bootc; do sleep 1 done - __engine stop publish + __engine stop "$TEST_ID" done diff --git a/tests/t/random-ssh-key-pair.sh b/tests/t/random-ssh-key-pair.sh index fcd7afd..3fe4c1d 100644 --- a/tests/t/random-ssh-key-pair.sh +++ b/tests/t/random-ssh-key-pair.sh @@ -2,10 +2,10 @@ __engine run \ --detach \ - --name random-ssh-key-pair \ + --name "$TEST_ID" \ "${TEST_IMAGES[fedora]}" \ --random-ssh-key-pair -__engine exec random-ssh-key-pair --as fedora -__engine restart random-ssh-key-pair -__engine exec random-ssh-key-pair --as fedora +__engine exec "$TEST_ID" --as fedora +__engine restart "$TEST_ID" +__engine exec "$TEST_ID" --as fedora diff --git a/tests/t/stop-start.sh b/tests/t/stop-start.sh index bdce535..d0e47fb 100644 --- a/tests/t/stop-start.sh +++ b/tests/t/stop-start.sh @@ -1,14 +1,14 @@ # SPDX-License-Identifier: GPL-2.0-or-later -__engine run --detach --name stop-start "${TEST_IMAGES[fedora]}" +__engine run --detach --name "$TEST_ID" "${TEST_IMAGES[fedora]}" -__engine exec stop-start --as fedora '[[ ! -e i-was-here ]] && touch i-was-here' +__engine exec "$TEST_ID" --as fedora '[[ ! -e i-was-here ]] && touch i-was-here' for (( i = 0; i < 2; ++i )); do - __engine stop stop-start - __engine start stop-start + __engine stop "$TEST_ID" + __engine start "$TEST_ID" - __engine exec stop-start --as fedora '[[ -e i-was-here ]]' + __engine exec "$TEST_ID" --as fedora '[[ -e i-was-here ]]' done