diskimage-builder/tests/run_output_format_test.sh
Gregory Haynes feb4eda17a Fail functests if refusing to run tests
We made this non-failing so tests could pass before
I92299b2f59aa8e7de8995a6294bf6c88bbd4cdc5 merges. We should make this a
test failure.

Change-Id: I4dd38c835d6fb397bbd0475120a4b0f2ab0290a8
Depends-On: I92299b2f59aa8e7de8995a6294bf6c88bbd4cdc5
2016-05-13 17:07:32 +00:00

77 lines
2 KiB
Bash
Executable file

#!/bin/bash
set -eu
set -o pipefail
#
# run_output_format_test.sh
#
# Use docker to test generation of various output formats.
#
BASE_DIR=$(cd $(dirname "$0")/.. && pwd)
export DIB_ELEMENTS=$BASE_DIR/elements
export TEST_ELEMENTS=$BASE_DIR/tests/elements
export DIB_CMD=$BASE_DIR/bin/disk-image-create
function build_test_image() {
format=${1:-}
if [ -n "$format" ]; then
type_arg="-t $format"
else
type_arg=
format="qcow2"
fi
dest_dir=$(mktemp -d)
base_dest=$(basename $dest_dir)
trap "rm -rf $dest_dir; sudo docker rmi $base_dest/image" EXIT
ELEMENTS_PATH=$DIB_ELEMENTS:$TEST_ELEMENTS \
$DIB_CMD -x $type_arg --docker-target=$base_dest/image \
-o $dest_dir/image -n fake-os
format=$(echo $format | tr ',' ' ')
for format in $format; do
if [ $format != 'docker' ]; then
img_path="$dest_dir/image.$format"
if ! [ -f "$img_path" ]; then
echo "Error: No image with name $img_path found!"
exit 1
else
echo "Found image $img_path."
fi
else
if ! sudo docker images | grep $base_dest/image ; then
echo "Error: No docker image with name $base_dest/image found!"
exit 1
else
echo "Found docker image $base_dest/image"
fi
fi
done
trap EXIT
rm -rf $dest_dir
if sudo docker images | grep $base_dest/image ; then
sudo docker rmi $base_dest/image
fi
}
test_formats="tar raw qcow2 docker aci"
for binary in qemu-img docker ; do
if [ -z "$(which $binary)" ]; then
echo "Warning: No $binary binary found, cowardly refusing to run tests."
exit 1
fi
done
for format in '' $test_formats; do
build_test_image $format
echo "Test passed for output formats '$format'."
done
combined_format=$(echo $test_formats | tr ' ' ',')
build_test_image $combined_format
echo "Test passed for output format '$combined_format'."