mirror of
https://github.com/containers/podman.git
synced 2025-06-26 04:46:57 +08:00
Merge pull request #16993 from edsantiago/bats_remote
[CI:DOCS] hack/bats: various improvements
This commit is contained in:
55
hack/bats
55
hack/bats
@ -12,6 +12,7 @@ $0 is a wrapper for invoking podman system tests.
|
||||
|
||||
--root Run only as root
|
||||
--rootless Run only as user (i.e. you)
|
||||
--remote Run with podman-remote (see below)
|
||||
|
||||
FILENAME-PATTERN Run only test files that match 'test/system/*name*',
|
||||
e.g. '500' or 'net' will match 500-networking.bats.
|
||||
@ -28,23 +29,27 @@ $0 is a wrapper for invoking podman system tests.
|
||||
|
||||
By default, tests ./bin/podman. To test a different podman, do:
|
||||
|
||||
\$ PODMAN=/abs/path/to/podman $0 ....
|
||||
\$ env PODMAN=/abs/path/to/podman $0 ....
|
||||
|
||||
To test podman-remote, start your own servers (root and rootless) via:
|
||||
|
||||
/path/to/podman system service --timeout=0
|
||||
\$ bin/podman system service --timeout=0 &
|
||||
\$ sudo !!
|
||||
|
||||
...then invoke this script with PODMAN=\$(pwd)/bin/podman-remote
|
||||
|
||||
(You'd think Ed could be bothered to do all that in this script; but then
|
||||
the flow would be 'sudo start-service; sudo run-bats; sudo stop-service'
|
||||
and by the time we get to stop-service, the sudo timeout will have lapsed,
|
||||
and the script will be hanging at the password prompt, and you, who left
|
||||
your desk for coffee or a walk and expected to come back to completed
|
||||
root and rootless tests, will be irked because only root tests ran and
|
||||
now you have to wait for rootless).
|
||||
...then invoke this script with --remote. (This script can't start the
|
||||
servers, because we can sudo *starting* the service but can't sudo
|
||||
stopping it: by the time the bats tests finish, the sudo timeout will
|
||||
have expired. We apologize for the inconvenience.)
|
||||
|
||||
$0 also passes through \$OCI_RUNTIME, should you need to test that.
|
||||
|
||||
Examples:
|
||||
|
||||
\$ $0 220:\"restart cleans up\"
|
||||
... only the \"restart cleans up\" test in 220-healthcheck.bats
|
||||
|
||||
\$ $0 --root 160:\"ps -f\"
|
||||
... runs all tests in 160-volumes.bats that match \"ps -f\" (root only)
|
||||
"
|
||||
|
||||
# END usage message
|
||||
@ -63,8 +68,8 @@ chcon -t container_runtime_exec_t $PODMAN
|
||||
TESTS=test/system
|
||||
|
||||
REMOTE=
|
||||
ROOT_ONLY=
|
||||
ROOTLESS_ONLY=
|
||||
TEST_ROOT=1
|
||||
TEST_ROOTLESS=1
|
||||
|
||||
declare -a bats_opts=()
|
||||
|
||||
@ -74,9 +79,9 @@ for i;do
|
||||
value=`expr "$i" : '[^=]*=\(.*\)'`
|
||||
case "$i" in
|
||||
-h|--help) echo "$usage"; exit 0;;
|
||||
--root) ROOT_ONLY=1 ;;
|
||||
--rootless) ROOTLESS_ONLY=1 ;;
|
||||
--remote) REMOTE=remote; echo "--remote is TBI"; exit 1;;
|
||||
--root) TEST_ROOTLESS= ;;
|
||||
--rootless) TEST_ROOT= ;;
|
||||
--remote) REMOTE=remote ;;
|
||||
--ts|-T) bats_opts+=("-T") ;;
|
||||
*/*.bats) TESTS=$i ;;
|
||||
*)
|
||||
@ -92,6 +97,20 @@ for i;do
|
||||
esac
|
||||
done
|
||||
|
||||
# With --remote, use correct binary and make sure daem--I mean server--is live
|
||||
if [[ "$REMOTE" ]]; then
|
||||
if ! [[ $PODMAN =~ -remote ]]; then
|
||||
PODMAN=${PODMAN}-remote
|
||||
fi
|
||||
|
||||
if [[ -n "$TEST_ROOT" ]]; then
|
||||
sudo $PODMAN info >/dev/null || exit 1
|
||||
fi
|
||||
if [[ -n "$TEST_ROOTLESS" ]]; then
|
||||
$PODMAN info >/dev/null || exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# END initialization and command-line arg checking
|
||||
###############################################################################
|
||||
|
||||
@ -106,7 +125,7 @@ fi
|
||||
export PODMAN_ROOTLESS_USER=$(id -un)
|
||||
|
||||
# Root
|
||||
if [ -z "$ROOTLESS_ONLY" ]; then
|
||||
if [[ "$TEST_ROOT" ]]; then
|
||||
echo "# bats ${bats_filter[*]} $TESTS"
|
||||
sudo --preserve-env=PODMAN \
|
||||
--preserve-env=QUADLET \
|
||||
@ -119,7 +138,7 @@ if [ -z "$ROOTLESS_ONLY" ]; then
|
||||
fi
|
||||
|
||||
# Rootless. (Only if we're not already root)
|
||||
if [[ -z "$ROOT_ONLY" && "$(id -u)" != 0 ]]; then
|
||||
if [[ "$TEST_ROOTLESS" && "$(id -u)" != 0 ]]; then
|
||||
echo "--------------------------------------------------"
|
||||
echo "\$ bats ${bats_filter[*]} $TESTS"
|
||||
bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS
|
||||
|
Reference in New Issue
Block a user