From ac87ba3f4c876a1e1b6d5113fd32681efdd63664 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Fri, 28 Feb 2025 20:11:35 -0700 Subject: [PATCH] fix tests - only leave fedora enabled - test each package one at a time to ensure they install correctly --- tests/cleanup.sh | 20 +++++++++++++------- tests/lib.sh | 10 ++++++++++ tests/setup.sh | 38 ++++++++++++++++++-------------------- tests/test.sh | 27 +++++++++++++++------------ 4 files changed, 56 insertions(+), 39 deletions(-) create mode 100644 tests/lib.sh diff --git a/tests/cleanup.sh b/tests/cleanup.sh index 1669872..af82ef8 100755 --- a/tests/cleanup.sh +++ b/tests/cleanup.sh @@ -1,10 +1,16 @@ #!/usr/bin/env zsh -IMAGE=packagetest -CONTAINER=packagetest -MACHINENAME=podman-machine-default +[[ -f ./lib.sh ]] && source ./lib.sh || exit 1 -ssh-keygen -R "[127.0.0.1]:2222" -podman stop $CONTAINER -podman rm $IMAGE -podman machine stop $MACHINENAME +for os in ${OSBUILDS[@]} +do + if podman container exists ${IMAGE}:${os} + then + podman stop ${IMAGE}:${os} + fi +done + +if [ "$HOSTOS" = "Darwin" ] +then + podman machine stop ${MACHINENAME} +fi diff --git a/tests/lib.sh b/tests/lib.sh new file mode 100644 index 0000000..4b6986b --- /dev/null +++ b/tests/lib.sh @@ -0,0 +1,10 @@ +HOSTOS="$(uname -o)" +IMAGE=${IMAGE:-packagetest} +CONTAINER=${CONTAINER:-packagetest} +MACHINENAME=${MACHINENAME:-podman-machine-default} +# OSBUILDS=("fedora" "el9" "debian" "ubuntu") +OSBUILDS=("fedora") + +function machine_state { + echo $(podman machine inspect $MACHINENAME | jq -r '.[].State') +} diff --git a/tests/setup.sh b/tests/setup.sh index c3f330a..0781961 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -1,26 +1,24 @@ #!/usr/bin/env zsh -IMAGE=packagetest -CONTAINER=packagetest -MACHINENAME=podman-machine-default +[[ -f ./lib.sh ]] && source ./lib.sh || exit 1 -function machine_state { - echo $(podman machine inspect $MACHINENAME | jq -r '.[].State') -} +if [ "$HOSTOS" = "Darwin" ] +then + echo "Starting $MACHINENAME" + podman machine start -q $MACHINENAME + while [ "$(machine_state)" != "running" ] + do + echo $(machine_state) + echo "Wating for $MACHINENAME to start" + sleep 1 + done -echo "Starting $MACHINENAME" -podman machine start -q $MACHINENAME -while [ "$(machine_state)" != "running" ] -do - echo $(machine_state) - echo "Wating for $MACHINENAME to start" - sleep 1 -done - -echo "Machine $MACHINENAME running" + echo "Machine $MACHINENAME running" +fi echo "Building container images" -#podman build --platform linux/amd64 -f Containerfile.el9 -t ${IMAGE}_el9 . -podman build --platform linux/amd64 -f Containerfile.fedora -t ${IMAGE}_fedora . -#podman build --platform linux/amd64 -f Containerfile.debian -t ${IMAGE}_debian . -#podman build --platform linux/amd64 -f Containerfile.ubuntu -t ${IMAGE}_ubuntu . +for os in ${OSBUILDS[@]} +do + echo "Building image for ${os}" + podman build --platform linux/amd64 -f Containerfile.${os} -t ${IMAGE}:${os} . +done diff --git a/tests/test.sh b/tests/test.sh index 9f8877f..e72dbf8 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,14 +1,17 @@ #!/usr/bin/env zsh -podman run --rm -it -d --platform linux/amd64 --name packagetest_fedora -p 2222:22 packagetest -ansible-playbook test_not_local.yml -i inventory.yml -podman stop packagetest -# podman run --rm -it -d --platform linux/amd64 --name packagetest -p 2222:22 packagetest -# ansible-playbook test_not_local.yml -i inventory.yml -# podman stop packagetest -# podman run --rm -it -d --platform linux/amd64 --name packagetest -p 2222:22 packagetest -# ansible-playbook test_not_local.yml -i inventory.yml -# podman stop packagetest -# podman run --rm -it -d --platform linux/amd64 --name packagetest -p 2222:22 packagetest -# ansible-playbook test_not_local.yml -i inventory.yml -# podman stop packagetest +[[ -f ./lib.sh ]] && source ./lib.sh || exit 1 + +for os in ${OSBUILDS[@]} +do + if ! podman container exists ${IMAGE}:${os} + then + podman run --rm -it -d --platform linux/amd64 --name ${IMAGE}:${os} -p 2222:22 packagetest + fi + ansible-playbook test_not_local.yml -i inventory.yml + if [ $? -eq 0 ] + then + podman stop ${IMAGE}:${os} + ssh-keygen -R "[127.0.0.1]:2222" + fi +done