diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-19 09:12:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 09:12:27 -0700 |
commit | 537c382f5bd098bc89a457554db9bd0b08eab3c2 (patch) | |
tree | 649331a8c1b88393f07fe061390e5ca8a51b2007 | |
parent | a1299f506d9b93824fae737f0f68a19adaf2bde1 (diff) | |
parent | 58d2e589fb4dbcc23cfc5ddd3f886a32a0ab759e (diff) | |
download | podman-537c382f5bd098bc89a457554db9bd0b08eab3c2.tar.gz podman-537c382f5bd098bc89a457554db9bd0b08eab3c2.tar.bz2 podman-537c382f5bd098bc89a457554db9bd0b08eab3c2.zip |
Merge pull request #2703 from edsantiago/bats
BATS: new tests, and improvements to existing ones
-rw-r--r-- | test/system/000-TEMPLATE | 2 | ||||
-rw-r--r-- | test/system/015-help.bats | 19 | ||||
-rw-r--r-- | test/system/035-logs.bats | 27 | ||||
-rw-r--r-- | test/system/060-mount.bats | 2 | ||||
-rw-r--r-- | test/system/075-exec.bats | 30 | ||||
-rw-r--r-- | test/system/120-load.bats | 96 | ||||
-rw-r--r-- | test/system/200-pod-top.bats | 14 | ||||
-rw-r--r-- | test/system/300-cli-parsing.bats | 15 |
8 files changed, 198 insertions, 7 deletions
diff --git a/test/system/000-TEMPLATE b/test/system/000-TEMPLATE index 296ed4d58..85e25e921 100644 --- a/test/system/000-TEMPLATE +++ b/test/system/000-TEMPLATE @@ -52,7 +52,7 @@ function teardown() { @test "podman FOO - description of test" { # FIXME: please try to remove this line; that is, try to write tests # that will pass as both root and rootless. - skip_if_rootless + skip_if_rootless "Short explanation of why this doesn't work rootless" # FIXME: template for run commands. Always use 'run_podman'! # FIXME: The '?' means 'ignore exit status'; use a number if you diff --git a/test/system/015-help.bats b/test/system/015-help.bats index b648599f7..8e07b8822 100644 --- a/test/system/015-help.bats +++ b/test/system/015-help.bats @@ -46,15 +46,34 @@ function check_help() { # Confirm that by running with 'invalid-arg' and expecting failure. if expr "$usage" : '.*\[flags\]$' >/dev/null; then if [ "$cmd" != "help" ]; then + dprint "podman $@ $cmd invalid-arg" run_podman 125 "$@" $cmd invalid-arg is "$output" "Error: .* takes no arguments" \ "'podman $@ $cmd' with extra (invalid) arguments" fi fi + # If usage has required arguments, try running without them + if expr "$usage" : '.*\[flags\] [A-Z]' >/dev/null; then + dprint "podman $@ $cmd (without required args)" + run_podman 125 "$@" $cmd + is "$output" "Error:" + fi + count=$(expr $count + 1) done + # Any command that takes subcommands, must throw error if called + # without one. + dprint "podman $@" + run_podman 125 "$@" + is "$output" "Error: missing command .*$@ COMMAND" + + # Assume that 'NoSuchCommand' is not a command + dprint "podman $@ NoSuchCommand" + run_podman 125 "$@" NoSuchCommand + is "$output" "Error: unrecognized command .*$@ NoSuchCommand" + # This can happen if the output of --help changes, such as between # the old command parser and cobra. [ $count -gt 0 ] || \ diff --git a/test/system/035-logs.bats b/test/system/035-logs.bats index debec29b6..055865c8d 100644 --- a/test/system/035-logs.bats +++ b/test/system/035-logs.bats @@ -18,7 +18,34 @@ load helpers is "$output" "$rand_string" "output from podman-start on created ctr" is "$output" "$rand_string" "logs of started container" + run_podman logs $cid + is "$output" "$rand_string" "output from podman-logs after container is run" + run_podman rm $cid } +@test "podman logs - multi" { + # Simple helper to make the container starts, below, easier to read + local -a cid + doit() { + run_podman run --rm -d --name "$1" $IMAGE sh -c "$2"; + cid+=($(echo "${output:0:12}")) + } + + # Not really a guarantee that we'll get a-b-c-d in order, but it's + # the best we can do. The trailing 'sleep' in each container + # minimizes the chance of a race condition in which the container + # is removed before 'podman logs' has a chance to wake up and read + # the final output. + doit c1 "echo a;sleep 10;echo d;sleep 3" + doit c2 "sleep 1;echo b;sleep 2;echo c;sleep 3" + + run_podman logs -f c1 c2 + is "$output" \ + "${cid[0]} a +${cid[1]} b +${cid[1]} c +${cid[0]} d" "Sequential output from logs" +} + # vim: filetype=sh diff --git a/test/system/060-mount.bats b/test/system/060-mount.bats index 3601b7b84..e249b2883 100644 --- a/test/system/060-mount.bats +++ b/test/system/060-mount.bats @@ -5,7 +5,7 @@ load helpers @test "podman mount - basic test" { # Only works with root (FIXME: does it work with rootless + vfs?) - skip_if_rootless + skip_if_rootless "mount does not work rootless" f_path=/tmp/tmpfile_$(random_string 8) f_content=$(random_string 30) diff --git a/test/system/075-exec.bats b/test/system/075-exec.bats new file mode 100644 index 000000000..a12d28b32 --- /dev/null +++ b/test/system/075-exec.bats @@ -0,0 +1,30 @@ +#!/usr/bin/env bats -*- bats -*- +# +# Tests for podman exec +# + +load helpers + +@test "podman exec - basic test" { + rand_filename=$(random_string 20) + rand_content=$(random_string 50) + + # Start a container. Write random content to random file, then stay + # alive as long as file exists. (This test will remove that file soon.) + run_podman run -d $IMAGE sh -c \ + "echo $rand_content >/$rand_filename;echo READY;while [ -f /$rand_filename ]; do sleep 1; done" + cid="$output" + wait_for_ready $cid + + run_podman exec $cid sh -c "cat /$rand_filename" + is "$output" "$rand_content" "Can exec and see file in running container" + + run_podman exec $cid rm -f /$rand_filename + + run_podman wait $cid + is "$output" "0" "output from podman wait (container exit code)" + + run_podman rm $cid +} + +# vim: filetype=sh diff --git a/test/system/120-load.bats b/test/system/120-load.bats new file mode 100644 index 000000000..dedfe6172 --- /dev/null +++ b/test/system/120-load.bats @@ -0,0 +1,96 @@ +#!/usr/bin/env bats -*- bats -*- +# +# tests for podman load +# + +load helpers + +# Custom helpers for this test only. These just save us having to duplicate +# the same thing four times (two tests, each with -i and stdin). +# +# initialize, read image ID and name +get_iid_and_name() { + run_podman images --format '{{.ID}} {{.Repository}}:{{.Tag}}' + read iid img_name < <(echo "$output") + + archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar +} + +# Simple verification of image ID and name +verify_iid_and_name() { + run_podman images --format '{{.ID}} {{.Repository}}:{{.Tag}}' + read new_iid new_img_name < <(echo "$output") + + # Verify + is "$new_iid" "$iid" "Image ID of loaded image == original" + is "$new_img_name" "$1" "Name & tag of restored image" +} + + +@test "podman load - by image ID" { + # FIXME: how to build a simple archive instead? + get_iid_and_name + + # Save image by ID, and remove it. + run_podman save $iid -o $archive + run_podman rmi $iid + + # Load using -i; IID should be preserved, but name is not. + run_podman load -i $archive + verify_iid_and_name "<none>:<none>" + + # Same as above, using stdin + run_podman rmi $iid + run_podman load < $archive + verify_iid_and_name "<none>:<none>" + + # Cleanup: since load-by-iid doesn't preserve name, re-tag it; + # otherwise our global teardown will rmi and re-pull our standard image. + run_podman tag $iid $img_name +} + +@test "podman load - by image name" { + get_iid_and_name + run_podman save $img_name -o $archive + run_podman rmi $iid + + # Load using -i; this time the image should be tagged. + run_podman load -i $archive + verify_iid_and_name $img_name + + # Same as above, using stdin + run_podman rmi $iid + run_podman load < $archive + verify_iid_and_name $img_name +} + +@test "podman load - NAME and NAME:TAG arguments work (requires: #2674)" { + get_iid_and_name + run_podman save $iid -o $archive + run_podman rmi $iid + + # Load with just a name (note: names must be lower-case) + random_name=$(random_string 20 | tr A-Z a-z) + run_podman load -i $archive $random_name + verify_iid_and_name "localhost/$random_name:latest" + + # Load with NAME:TAG arg + run_podman rmi $iid + random_tag=$(random_string 10 | tr A-Z a-z) + run_podman load -i $archive $random_name:$random_tag + verify_iid_and_name "localhost/$random_name:$random_tag" + + # Cleanup: restore desired image name + run_podman tag $iid $img_name + run_podman rmi "$random_name:$random_tag" +} + + +@test "podman load - will not read from tty" { + run_podman 125 load + is "$output" \ + "Error: cannot read from terminal. Use command-line redirection" \ + "Diagnostic from 'podman load' without redirection or -i" +} + +# vim: filetype=sh diff --git a/test/system/200-pod-top.bats b/test/system/200-pod-top.bats index 81c4be3ff..0200df00d 100644 --- a/test/system/200-pod-top.bats +++ b/test/system/200-pod-top.bats @@ -3,9 +3,10 @@ load helpers @test "podman pod top - containers in different PID namespaces" { - skip_if_rootless - - run_podman pod create + # With infra=false, we don't get a /pause container (we also + # don't pull k8s.gcr.io/pause ) + no_infra='--infra=false' + run_podman pod create $no_infra podid="$output" # Start two containers... @@ -23,11 +24,14 @@ load helpers run_podman pod top $podid is "$output" ".*root.*top -d 2.*root.*top -d 2" "two 'top' containers" - # There should be a /pause container + # By default (podman pod create w/ default --infra) there should be + # a /pause container. # FIXME: sometimes there is, sometimes there isn't. If anyone ever # actually figures this out, please either reenable this line or # remove it entirely. - #is "$output" ".*0 \+1 \+0 \+[0-9. ?s]\+/pause" "there is a /pause container" + if [ -z "$no_infra" ]; then + is "$output" ".*0 \+1 \+0 \+[0-9. ?s]\+/pause" "there is a /pause container" + fi # Clean up run_podman pod rm -f $podid diff --git a/test/system/300-cli-parsing.bats b/test/system/300-cli-parsing.bats new file mode 100644 index 000000000..92c073102 --- /dev/null +++ b/test/system/300-cli-parsing.bats @@ -0,0 +1,15 @@ +#!/usr/bin/env bats -*- bats -*- +# +# Various command-line parsing regression tests that don't fit in elsewhere +# + +load helpers + +@test "podman cli parsing - quoted args - #2574" { + # 1.1.2 fails with: + # Error: invalid argument "true=\"false\"" for "-l, --label" \ + # flag: parse error on line 1, column 5: bare " in non-quoted-field + run_podman run --rm --label 'true="false"' $IMAGE true +} + +# vim: filetype=sh |