From 7203469f1098cdeda32e17d0d3fda49c718e0916 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Tue, 13 Nov 2018 06:28:26 -0700 Subject: [PATCH] Quick simple tests for podman This is a placeholder only. The idea is that, once the ginkgo tests are approved and merged and packaged, you add that package to test_podman.yml:required_packages, then rewrite the .sh script so it invokes those tests and writes PASS/FAIL to test.log as appropriate. Until then, this can serve as a rudimentary gate. Signed-off-by: Ed Santiago --- tests/test_podman.sh | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/test_podman.yml | 27 ++++++++++++++ tests/tests.yml | 1 + 3 files changed, 110 insertions(+) create mode 100755 tests/test_podman.sh create mode 100644 tests/test_podman.yml create mode 100644 tests/tests.yml diff --git a/tests/test_podman.sh b/tests/test_podman.sh new file mode 100755 index 0000000..abb33cb --- /dev/null +++ b/tests/test_podman.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# Simple podman tests +# + +set -x + +exec >/tmp/test.debug.log 2>&1 + +echo "************************************************************************" +echo "* This log contains the debug output from test_podman.sh." +echo "*" +echo "* Short test PASS/FAIL summary is in test.log" +echo "************************************************************************" + +rm -f /tmp/test.log +touch /tmp/test.log + +counter_file=/tmp/test.counter.txt +echo 0 >| $counter_file + +do_test() { + local cmd="$1"; shift + local expected_status="$1"; shift + local expected_stdout="$1"; shift + + counter=$(expr $(< $counter_file) + 1) + echo $counter >| $counter_file + + # Make debug log easier to read + echo + echo "--------------------------------------------------------------------" + echo "-- test $counter" + echo + + stdout=$(eval podman $cmd) + status=$? + if [ $status -ne $expected_status ]; then + echo "FAIL $counter $cmd: status=$status (expected $expected_status)" >>/tmp/test.log + return + fi + + if [ "$expected_stdout" = "-" ]; then + : + elif [ -z "$expected_stdout" ]; then + if [ -n "$stdout" ]; then + echo "FAIL $counter $cmd : stdout='$stdout' (expected '')" >>/tmp/test.log + return + fi + else + if ! expr "$stdout" : "$expected_stdout"; then + echo "FAIL $counter $cmd : stdout='$stdout' (expected '$expected_stdout')" >>/tmp/test.log + return + fi + fi + + echo "PASS $counter $cmd" >>/tmp/test.log +} + +# Clean slate +do_test "rm -a -f" 0 "-" +do_test "rmi -a -f" 0 "-" + +do_test "info --format '{{.host.rootless}}'" 0 "false" +do_test "info --format '{{.store.GraphDriverName}}'" 0 "overlay" + +do_test "pull alpine" 0 "-" +do_test "images --format {{.Repository}}:{{.Tag}}" 0 \ + "docker.io/library/alpine:latest" + +do_test "run alpine sh -c 'echo hi'" 0 "hi" +do_test "run alpine date" 0 "-" +do_test "run alpine /bin/false" 1 "" + +do_test "ps -a | wc -l" 0 "4" +do_test "ps -a | grep false | grep -q 'Exited (1)'" 0 "" + +# Final exit status: nonzero if the word FAIL is present in results +if grep -q FAIL /tmp/test.log; then + exit 1 +fi +exit 0 diff --git a/tests/test_podman.yml b/tests/test_podman.yml new file mode 100644 index 0000000..f77c322 --- /dev/null +++ b/tests/test_podman.yml @@ -0,0 +1,27 @@ +--- +- hosts: localhost + vars: + - artifacts: ./artifacts + - required_packages: + - podman + tags: + - classic + - container + + tasks: + - name: install packages + dnf: name="{{ required_packages }}" state=installed + enablerepo=updates-testing + + - block: + - name: Run test + script: ./test_podman.sh + always: + - name: Pull out logs + fetch: + src: "/tmp/{{ item }}" + dest: "{{ artifacts }}/{{ item }}" + flat: yes + with_items: + - test.log + - test.debug.log diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..80caee7 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1 @@ +- import_playbook: test_podman.yml