From a210a4d7c2891b95a6cbe597243e24b6de6dfc8a Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 26 Feb 2024 15:59:01 +0100 Subject: [PATCH] test/compose: add test for default connection Make sure that we use the --connection correctly with podman compose. Signed-off-by: Paul Holzinger --- test/compose/test-compose | 35 +++++++++++++++++++++++++++++------ test/compose/uptwice/tests.sh | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/test/compose/test-compose b/test/compose/test-compose index a123a8de2a..3275f987f6 100755 --- a/test/compose/test-compose +++ b/test/compose/test-compose @@ -247,6 +247,15 @@ function podman() { return $rc } +# as rootless we want to test the remote connection so we add --connection +function podman_compose() { + if is_rootless; then + $PODMAN_BIN --connection compose-sock compose "$@" + else + podman compose "$@" + fi +} + ################### # random_string # Returns a pseudorandom human-readable string ################### @@ -271,12 +280,26 @@ done # When rootless use a socket path accessible by the rootless user if is_rootless; then + # lets test two cases here, for rootless we try to connect to the connection as this should be respected DOCKER_SOCK="$WORKDIR/docker.sock" + # use PODMAN_CONNECTIONS_CONF so we do not overwrite user settings + PODMAN_CONNECTIONS_CONF="$WORKDIR/connections.json" + export PODMAN_CONNECTIONS_CONF + $PODMAN_BIN system connection add --default notexists "unix:///I/do/not/exist" + $PODMAN_BIN system connection add compose-sock "unix://$DOCKER_SOCK" + +else + # export DOCKER_HOST docker-compose will use it + DOCKER_HOST="unix://$DOCKER_SOCK" + export DOCKER_HOST fi -# export DOCKER_HOST docker-compose will use it -DOCKER_HOST="unix://$DOCKER_SOCK" -export DOCKER_HOST +# hide annoying podman compose warnings, some tests want to check compose stderr and this breaks it. +CONTAINERS_CONF_OVERRIDE="$WORKDIR/containers.conf" +echo '[engine] +compose_warning_logs=false' > "$CONTAINERS_CONF_OVERRIDE" +export CONTAINERS_CONF_OVERRIDE + # Identify the tests to run. If called with args, use those as globs. tests_to_run=() @@ -336,12 +359,12 @@ for t in "${tests_to_run[@]}"; do trap - ERR fi - podman compose up -d &> $logfile + podman_compose up -d &> $logfile docker_compose_rc=$? if [[ $docker_compose_rc -ne 0 ]]; then _show_ok 0 "$testname - up" "[ok]" "status=$docker_compose_rc" sed -e 's/^/# /' <$logfile - podman compose down >>$logfile 2>&1 # No status check here + podman_compose down >>$logfile 2>&1 # No status check here exit 1 fi _show_ok 1 "$testname - up" @@ -361,7 +384,7 @@ for t in "${tests_to_run[@]}"; do fi # Done. Clean up. - podman compose down &>> $logfile + podman_compose down &>> $logfile rc=$? if [[ $rc -eq 0 ]]; then _show_ok 1 "$testname - down" diff --git a/test/compose/uptwice/tests.sh b/test/compose/uptwice/tests.sh index 013b5a29a8..0bf1b12146 100644 --- a/test/compose/uptwice/tests.sh +++ b/test/compose/uptwice/tests.sh @@ -5,7 +5,7 @@ NL=$'\n' cp docker-compose.yml docker-compose.yml.bak sed -i -e 's/10001/10002/' docker-compose.yml -output=$(docker-compose up -d 2>&1) +output=$(podman_compose up -d 2>&1) # Horrible output check here but we really want to make sure that there are # no unexpected warning/errors and the normal messages are send on stderr as