Skip to content

Commit

Permalink
tests/env.sh: Expose TEST_ID variable to tests
Browse files Browse the repository at this point in the history
Its value is a random identifier unique to the current run of the
current test.

Signed-off-by: Alberto Faria <[email protected]>
  • Loading branch information
albertofaria committed Jul 11, 2024
1 parent 132cc4c commit 7b02635
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 48 deletions.
1 change: 1 addition & 0 deletions tests/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" )\
Expand Down
10 changes: 5 additions & 5 deletions tests/t/bootc-disk-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions tests/t/cloud-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/t/emulated.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions tests/t/hostname.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/t/ignition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions tests/t/mount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions tests/t/persistent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ fi

# Usage: __run <crun_vm_option> [<extra_podman_options...>]
__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 <crun_vm_option> <condition>
__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
Expand All @@ -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
12 changes: 6 additions & 6 deletions tests/t/publish.sh
Original file line number Diff line number Diff line change
@@ -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...'

Expand All @@ -28,6 +28,6 @@ for os in fedora fedora-bootc; do
sleep 1
done

__engine stop publish
__engine stop "$TEST_ID"

done
8 changes: 4 additions & 4 deletions tests/t/random-ssh-key-pair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions tests/t/stop-start.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7b02635

Please sign in to comment.