File: bats

package info (click to toggle)
podman 5.7.0%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,824 kB
  • sloc: sh: 4,700; python: 2,798; perl: 1,885; ansic: 1,484; makefile: 977; ruby: 42; csh: 8
file content (161 lines) | stat: -rwxr-xr-x 5,156 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# bats wrapper - invokes bats, root & rootless, on podman system tests
#

###############################################################################
# BEGIN usage message

usage="Usage: $0 [--root] [--rootless] [FILENAME-PATTERN[:TEST-PATTERN]]...

$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.

   TEST-PATTERN     When appended to a filename-pattern, and you have a
                    modern-enough version of bats installed (i.e. Fedora
                    but not RHEL), runs with '--filter TEST-PATTERN' which
                    runs only subtests within FILENAME-PATTERH whose names
                    match that string.

   --tag=TAG      Passed on to bats as '--filter-tags TAG'
                  As of 2025-09-01 the only tag used is 'ci:parallel'

   -t, --tap      Passed on to bats, which will format output in TAP format

   -T             Passed on to bats, which will then show timing data

   --help         display usage message

By default, tests ./bin/podman. To test a different podman, do:

    \$ env PODMAN=/abs/path/to/podman $0 ....

To test podman-remote, start your own servers (root and rootless) via:

    \$ bin/podman system service --timeout=0 &
    \$ sudo !!

...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.)

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
###############################################################################
# BEGIN initialization and command-line arg checking

# By default, test the podman in our working directory.
# Some tests cd out of our workdir, so abs path is important
export PODMAN=${PODMAN:-$(pwd)/bin/podman}
export QUADLET=${QUADLET:-$(pwd)/bin/quadlet}

# Directory in which
TESTS_DIR=test/system

REMOTE=
TEST_ROOT=1
TEST_ROOTLESS=1

declare -a bats_opts=()

declare -a bats_filter=()

declare -a TESTS

for i;do
    value=`expr "$i" : '[^=]*=\(.*\)'`
    case "$i" in
        -h|--help)  echo "$usage"; exit 0;;
        --root)     TEST_ROOTLESS= ;;
        --rootless) TEST_ROOT= ;;
        --remote)   REMOTE=remote ;;
        --tap|-t)   bats_opts+=("-t") ;;
        --ts|-T)    bats_opts+=("-T") ;;
        --tag=*)    bats_filter=("--filter-tags" "$value")
                    if [[ "$value" = "ci:parallel" ]]; then
                        bats_opts+=("--jobs" $(nproc))
                    fi;;
        */*.bats)   TESTS+=("$i") ;;
        *)
            if [[ $i =~ : ]]; then
                tname=${i%:*}          # network:localhost -> network
                filt=${i#*:}           # network:localhost ->   localhost
                TESTS+=($(echo $TESTS_DIR/*$tname*.bats))
                bats_filter=("--filter" "$filt")
            else
                TESTS+=($(echo $TESTS_DIR/*$i*.bats))
            fi
            ;;
    esac
done

if [ ${#TESTS[@]} -eq 0 ] ; then
        TESTS=("$TESTS_DIR")
fi

# 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
###############################################################################

rc=0

# As of 2021-11 podman has a bunch of external helper binaries
if [[ -z "$CONTAINERS_HELPER_BINARY_DIR" ]]; then
    export CONTAINERS_HELPER_BINARY_DIR=$(pwd)/bin
fi

# Used in 120-load test to identify rootless destination for podman image scp
export PODMAN_ROOTLESS_USER=${PODMAN_ROOTLESS_USER:-$(id -un)}

# Make sure to always check for leaks when running locally
export PODMAN_BATS_LEAK_CHECK=1

# Root
if [[ "$TEST_ROOT" ]]; then
    echo "# bats ${bats_opts[*]} ${bats_filter[*]} ${TESTS[*]}"
    sudo    --preserve-env=PODMAN \
            --preserve-env=QUADLET \
            --preserve-env=PODMAN_TEST_DEBUG \
            --preserve-env=CONTAINERS_HELPER_BINARY_DIR \
            --preserve-env=PODMAN_ROOTLESS_USER \
            bats "${bats_opts[@]}" "${bats_filter[@]}" "${TESTS[@]}"
    rc=$?
fi

# Rootless. (Only if we're not already root)
if [[ "$TEST_ROOTLESS" && "$(id -u)" != 0 ]]; then
    echo "--------------------------------------------------"
    echo "\$ bats ${bats_opts[*]} ${bats_filter[*]} ${TESTS[@]}"
    bats "${bats_opts[@]}" "${bats_filter[@]}" "${TESTS[@]}"
    rc=$((rc | $?))
fi

exit $rc