github.com/containers/podman/v5@v5.1.0-rc1/test/system/001-basic.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Simplest set of podman tests. If any of these fail, we have serious problems. 4 # 5 6 load helpers 7 load helpers.network 8 9 # Override standard setup! We don't yet trust podman-images or podman-rm 10 function setup() { 11 # Makes test logs easier to read 12 BATS_TEST_NAME_PREFIX="[001] " 13 } 14 15 #### DO NOT ADD ANY TESTS HERE! ADD NEW TESTS AT BOTTOM! 16 17 # bats test_tags=distro-integration 18 @test "podman version emits reasonable output" { 19 run_podman version 20 21 # First line of podman version is "Client: *Podman Engine". 22 # Just delete it (i.e. remove the first entry from the 'lines' array) 23 if expr "${lines[0]}" : "Client: *" >/dev/null; then 24 lines=("${lines[@]:1}") 25 fi 26 27 is "${lines[0]}" "Version:[ ]\+[1-9][0-9.]\+" "Version line 1" 28 is "$output" ".*Go Version: \+" "'Go Version' in output" 29 is "$output" ".*API Version: \+" "API version in output" 30 31 # Test that build date is reasonable, e.g. after 2019-01-01 32 local built=$(expr "$output" : ".*Built: \+\(.*\)" | head -n1) 33 local built_t=$(date --date="$built" +%s) 34 assert "$built_t" -gt 1546300800 "Preposterous 'Built' time in podman version" 35 36 run_podman -v 37 is "$output" "podman.*version \+" "'Version line' in output" 38 } 39 40 # bats test_tags=distro-integration 41 @test "podman info" { 42 # These will be displayed on the test output stream, offering an 43 # at-a-glance overview of important system configuration details 44 local -a want=( 45 'Arch:{{.Host.Arch}}' 46 'OS:{{.Host.Distribution.Distribution}}{{.Host.Distribution.Version}}' 47 'Runtime:{{.Host.OCIRuntime.Name}}' 48 'Rootless:{{.Host.Security.Rootless}}' 49 'Events:{{.Host.EventLogger}}' 50 'Logdriver:{{.Host.LogDriver}}' 51 'Cgroups:{{.Host.CgroupsVersion}}+{{.Host.CgroupManager}}' 52 'Net:{{.Host.NetworkBackend}}' 53 'DB:{{.Host.DatabaseBackend}}' 54 'Store:{{.Store.GraphDriverName}}' 55 ) 56 run_podman info --format "$(IFS='/' echo ${want[@]})" 57 echo "# $output" >&3 58 } 59 60 61 @test "podman --context emits reasonable output" { 62 if ! is_remote; then 63 skip "only applicable on podman-remote" 64 fi 65 # All we care about here is that the command passes 66 run_podman --context=default version 67 68 # This one must fail 69 PODMAN=${PODMAN%%--url*} run_podman 125 --context=swarm version 70 is "$output" \ 71 "Error: read cli flags: connection \"swarm\" not found" \ 72 "--context=swarm should fail" 73 } 74 75 # bats test_tags=distro-integration 76 @test "podman can pull an image" { 77 run_podman rmi -a -f 78 79 # This is a risk point: it will fail if the registry or network are flaky 80 run_podman pull $IMAGE 81 82 # Regression test for https://github.com/containers/image/pull/1615 83 # Make sure no progress lines are duplicated 84 local -A line_seen 85 for line in "${lines[@]}"; do 86 if [[ -n "${line_seen[$line]}" ]]; then 87 die "duplicate podman-pull output line: $line" 88 fi 89 line_seen[$line]=1 90 done 91 92 # Also make sure that the tag@digest syntax is supported. 93 run_podman inspect --format "{{ .Digest }}" $IMAGE 94 digest=$output 95 run_podman pull $IMAGE@$digest 96 97 # Now untag the digest reference again. 98 run_podman untag $IMAGE $IMAGE@$digest 99 100 # Make sure the original image is still present (#11557). 101 run_podman image exists $IMAGE 102 } 103 104 # PR #7212: allow --remote anywhere before subcommand, not just as 1st flag 105 @test "podman-remote : really is remote, works as --remote option" { 106 if ! is_remote; then 107 skip "only applicable on podman-remote" 108 fi 109 110 # First things first: make sure our podman-remote actually is remote! 111 run_podman version 112 is "$output" ".*Server:" "the given podman path really contacts a server" 113 114 # $PODMAN may be a space-separated string, e.g. if we include a --url. 115 # Split it into its components; remove "-remote" from the command path; 116 # and preserve any other args if present. 117 local -a podman_as_array=($PODMAN) 118 local podman_path=${podman_as_array[0]} 119 local podman_non_remote=${podman_path%%-remote} 120 local -a podman_args=("${podman_as_array[@]:1}") 121 122 # This always worked: running "podman --remote ..." 123 PODMAN="${podman_non_remote} --remote ${podman_args[@]}" run_podman version 124 is "$output" ".*Server:" "podman --remote: contacts server" 125 126 # This was failing: "podman --foo --bar --remote". 127 PODMAN="${podman_non_remote} --log-level=error ${podman_args[@]} --remote" run_podman version 128 is "$output" ".*Server:" "podman [flags] --remote: contacts server" 129 130 # ...but no matter what, --remote is never allowed after subcommand 131 PODMAN="${podman_non_remote} ${podman_args[@]}" run_podman 125 version --remote 132 is "$output" "Error: unknown flag: --remote 133 See 'podman version --help'" "podman version --remote" 134 } 135 136 @test "podman-remote: defaults" { 137 skip_if_remote "only applicable on a local run" 138 139 # By default, podman should include '--remote' in its help output 140 run_podman --help 141 assert "$output" =~ " --remote " "podman --help includes the --remote option" 142 143 # When it detects CONTAINER_HOST or _CONNECTION, --remote is not an option 144 CONTAINER_HOST=foobar run_podman --help 145 assert "$output" !~ " --remote " \ 146 "podman --help, with CONTAINER_HOST set, should not show --remote" 147 148 CONTAINER_CONNECTION=foobar run_podman --help 149 assert "$output" !~ " --remote " \ 150 "podman --help, with CONTAINER_CONNECTION set, should not show --remote" 151 152 # When it detects --url or --connection, --remote is not an option 153 run_podman --url foobar --help 154 assert "$output" !~ " --remote " \ 155 "podman --help, with --url set, should not show --remote" 156 157 run_podman --connection foobar --help 158 assert "$output" !~ " --remote " \ 159 "podman --help, with --connection set, should not show --remote" 160 } 161 162 # Check that just calling "podman-remote" prints the usage message even 163 # without a running endpoint. Use "podman --remote" for this as this works the same. 164 @test "podman-remote: check for command usage message without a running endpoint" { 165 if is_remote; then 166 skip "only applicable on a local run since this requires no endpoint" 167 fi 168 169 run_podman 125 --remote 170 is "$output" ".*Usage:" "podman --remote show usage message without running endpoint" 171 } 172 173 # This is for development only; it's intended to make sure our timeout 174 # in run_podman continues to work. This test should never run in production 175 # because it will, by definition, fail. 176 @test "timeout" { 177 if [ -z "$PODMAN_RUN_TIMEOUT_TEST" ]; then 178 skip "define \$PODMAN_RUN_TIMEOUT_TEST to enable this test" 179 fi 180 PODMAN_TIMEOUT=10 run_podman run $IMAGE sleep 90 181 echo "*** SHOULD NEVER GET HERE" 182 } 183 184 185 # Too many tests rely on jq for parsing JSON. 186 # 187 # If absolutely necessary, one could establish a convention such as 188 # defining PODMAN_TEST_SKIP_JQ=1 and adding a skip_if_no_jq() helper. 189 # For now, let's assume this is not absolutely necessary. 190 @test "jq is installed and produces reasonable output" { 191 type -path jq >/dev/null || die "FATAL: 'jq' tool not found." 192 193 run jq -r .a.b < <(echo '{ "a": { "b" : "you found me" } }') 194 is "$output" "you found me" "sample invocation of 'jq'" 195 } 196 197 @test "podman --log-level recognizes log levels" { 198 run_podman 1 --log-level=telepathic info 199 is "$output" 'Log Level "telepathic" is not supported.*' 200 201 run_podman --log-level=trace info 202 if ! is_remote; then 203 # podman-remote does not do any trace logging 204 assert "$output" =~ " level=trace " "log-level=trace" 205 fi 206 assert "$output" =~ " level=debug " "log-level=trace includes debug" 207 assert "$output" =~ " level=info " "log-level=trace includes info" 208 assert "$output" !~ " level=warn" "log-level=trace does not show warn" 209 210 run_podman --log-level=debug info 211 assert "$output" !~ " level=trace " "log-level=debug does not show trace" 212 assert "$output" =~ " level=debug " "log-level=debug" 213 assert "$output" =~ " level=info " "log-level=debug includes info" 214 assert "$output" !~ " level=warn" "log-level=debug does not show warn" 215 216 run_podman --log-level=info info 217 assert "$output" !~ " level=trace " "log-level=info does not show trace" 218 assert "$output" !~ " level=debug " "log-level=info does not show debug" 219 assert "$output" =~ " level=info " "log-level=info" 220 221 run_podman --log-level=warn info 222 assert "$output" !~ " level=" "log-level=warn shows no logs at all" 223 224 run_podman --log-level=warning info 225 assert "$output" !~ " level=" "log-level=warning shows no logs at all" 226 227 run_podman --log-level=error info 228 assert "$output" !~ " level=" "log-level=error shows no logs at all" 229 230 # docker compat 231 run_podman --debug info 232 assert "$output" =~ " level=debug " "podman --debug gives debug output" 233 run_podman -D info 234 assert "$output" =~ " level=debug " "podman -D gives debug output" 235 236 run_podman 1 --debug --log-level=panic info 237 is "$output" "Setting --log-level and --debug is not allowed" 238 } 239 240 # Tests --noout for commands that do not enter the engine 241 @test "podman --noout properly suppresses output" { 242 run_podman --noout system connection ls 243 is "$output" "" "output should be empty" 244 } 245 246 # Tests --noout to ensure that the output fd can be written to. 247 @test "podman --noout is actually writing to /dev/null" { 248 skip_if_remote "unshare only works locally" 249 skip_if_not_rootless "unshare requires rootless" 250 run_podman --noout unshare ls 251 is "$output" "" "output should be empty" 252 } 253 254 @test "podman version --out writes matching version to a json" { 255 run_podman version 256 257 # copypasta from version check. we're doing this to extract the version. 258 if expr "${lines[0]}" : "Client: *" >/dev/null; then 259 lines=("${lines[@]:1}") 260 fi 261 262 # get the version number so that we have something to compare with. 263 IFS=: read version_key version_number <<<"${lines[0]}" 264 is "$version_key" "Version" "Version line" 265 266 # now we can output everything as some json. we can't use PODMAN_TMPDIR since basic_setup 267 # isn't being used in setup() due to being unable to trust podman-images or podman-rm. 268 outfile=$(mktemp -p ${BATS_TEST_TMPDIR} veroutXXXXXXXX) 269 run_podman --out $outfile version -f json 270 271 # extract the version from the file. 272 run jq -r --arg field "$version_key" '.Client | .[$field]' $outfile 273 is "$output" ${version_number} "Version matches" 274 } 275 276 @test "podman - shutdown engines" { 277 run_podman --log-level=debug run --rm $IMAGE true 278 is "$output" ".*Shutting down engines.*" 279 run_podman 125 --log-level=debug run dockah://rien.de/rien:latest 280 is "${lines[-1]}" ".*Shutting down engines" 281 } 282 283 # vim: filetype=sh