From 2a8c00cc7032aec8688a661a190da9df35a594c1 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Mon, 15 Apr 2024 20:02:06 +0100 Subject: [PATCH 1/2] tests: Remove LAST_RUN_ID variable Signed-off-by: Alberto Faria --- tests/env.sh | 21 ++++++++------------- tests/t/hostname.sh | 14 ++++++++------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/env.sh b/tests/env.sh index 766853e..752e3c5 100755 --- a/tests/env.sh +++ b/tests/env.sh @@ -69,14 +69,14 @@ __elapsed() { # Usage: __small_log_without_time __small_log_without_time() { # shellcheck disable=SC2059 - printf "\033[%sm--- %s\033[0m\n" \ + >&2 printf "\033[%sm--- %s\033[0m\n" \ "$1" "$( printf "${@:2}" )" } # Usage: __log __small_log() { # shellcheck disable=SC2059 - printf "\033[%sm--- [%6.1f] %s\033[0m\n" \ + >&2 printf "\033[%sm--- [%6.1f] %s\033[0m\n" \ "$1" "$( __elapsed )" "$( printf "${@:2}" )" } @@ -86,8 +86,8 @@ __big_log() { text="$( printf "${@:2}" )" term_cols="$( tput cols 2> /dev/null )" || term_cols=80 sep_len="$(( term_cols - ${#text} - 16 ))" - printf "\033[%sm--- [%6.1f] %s " "$1" "$( __elapsed )" "${text}" - printf '%*s\033[0m\n' "$(( sep_len < 0 ? 0 : sep_len ))" '' | tr ' ' - + >&2 printf "\033[%sm--- [%6.1f] %s " "$1" "$( __elapsed )" "${text}" + >&2 printf '%*s\033[0m\n' "$(( sep_len < 0 ? 0 : sep_len ))" '' | tr ' ' - } __log_without_time_and_run() { @@ -339,16 +339,11 @@ run) # shellcheck disable=SC2317 __engine() { if [[ "$1" == run ]]; then - __command=( - "${engine_cmd[@]}" run - --runtime "$runtime_in_env" - --pull never - --label "$label" + __log_and_run "${engine_cmd[@]}" run \ + --runtime "$runtime_in_env" \ + --pull never \ + --label "$label" \ "${@:2}" - ) - __small_log 36 '$ %s' "${__command[*]}" - # shellcheck disable=SC2034 - LAST_RUN_ID=$( "${__command[@]}" ) else __log_and_run "${engine_cmd[@]}" "$@" fi diff --git a/tests/t/hostname.sh b/tests/t/hostname.sh index db97885..40f91d6 100644 --- a/tests/t/hostname.sh +++ b/tests/t/hostname.sh @@ -7,15 +7,17 @@ for os in fedora coreos; do # default hostname - __engine run \ - --rm --detach \ - --name "hostname-$os-default" \ - "$image" \ - "" + id=$( + __engine run \ + --rm --detach \ + --name "hostname-$os-default" \ + "$image" \ + "" + ) __test() { __engine exec "hostname-$os-default" --as "$user" \ - "set -x && [[ \$( hostname ) == ${LAST_RUN_ID::12} ]]" + "set -x && [[ \$( hostname ) == ${id::12} ]]" } __test From bc246172f6886ddfb6b45c188688c561cd65d8ae Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Mon, 15 Apr 2024 19:00:08 +0100 Subject: [PATCH 2/2] tests: Add a test for --publish Signed-off-by: Alberto Faria --- tests/env.sh | 3 +++ tests/t/publish.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/t/publish.sh diff --git a/tests/env.sh b/tests/env.sh index 752e3c5..b13372e 100755 --- a/tests/env.sh +++ b/tests/env.sh @@ -377,6 +377,9 @@ run) __skip() { exit 0 } + __log() { + __small_log 36 \"\$@\" + } TEMP_DIR=~/$label.temp UTIL_DIR=~/$label.util ENGINE=$engine diff --git a/tests/t/publish.sh b/tests/t/publish.sh new file mode 100644 index 0000000..34f04c6 --- /dev/null +++ b/tests/t/publish.sh @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +image="${TEST_IMAGES[fedora]}" +user="${TEST_IMAGES_DEFAULT_USER[fedora]}" + +__engine run \ + --rm --detach \ + --name publish \ + --publish 127.0.0.1::8000 \ + "$image" \ + "" + +endpoint=$( __engine port publish | tee /dev/stderr | cut -d' ' -f3 ) + +__engine exec publish --as "$user" + +__log 'Ensuring curl fails...' +! curl "$endpoint" 2>/dev/null + +__engine exec publish --as "$user" python -m http.server & +trap '__engine stop publish' EXIT + +sleep 3 + +__log 'Ensuring curl succeeds...' +[[ "$( curl "$endpoint" 2>/dev/null | head -1 )" == "" ]]