diff --git a/bin/lib.sh b/bin/lib.sh index 4f0d24bb..f1ea27f9 100644 --- a/bin/lib.sh +++ b/bin/lib.sh @@ -1,5 +1,3 @@ -#!/usr/bin/env bash -set -Eeu echo_versioner_env_vars() { @@ -130,24 +128,42 @@ exit_non_zero_unless_started_cleanly() # Handle known warnings (eg waiting on Gem upgrade) # local -r SHADOW_WARNING="server.rb:(.*): warning: shadowing outer local variable - filename" # DOCKER_LOG=$(strip_known_warning "${DOCKER_LOG}" "${SHADOW_WARNING}") + local -r SERVICE_NAME="${1}" echo echo "Checking if ${SERVICE_NAME} started cleanly." - if [ "$(top_5)" != "$(clean_top_5)" ]; then + + local -r DOCKER_LOG=$(docker logs "${CONTAINER_NAME}" 2>&1) + local -r top_5=$(echo "${DOCKER_LOG}" | head -5) + + if ! array_prefix "$(clean_top_5)" "${top_5}" ; then echo "${SERVICE_NAME} did not start cleanly: docker log..." echo 'expected------------------' - echo "$(clean_top_5)" + clean_top_5 echo echo 'actual--------------------' - echo "$(top_5)" + echo "${top_5}" echo echo 'diff--------------------' - grep -Fxvf <(clean_top_5) <(top_5) + grep -Fxvf <(clean_top_5) <(echo "${top_5}") echo exit 42 fi } +array_prefix() +{ + readarray -t expected_lines <<<"${1}" + readarray -t actual_lines <<<"${2}" + for i in {0..4} + do + if ! [[ "${actual_lines[$i]}" =~ ^"${expected_lines[$i]}" ]] ; then + return 1 # false + fi + done + return 0 # true +} + top_5() { docker logs "${CONTAINER_NAME}" 2>&1 | head -5 @@ -158,7 +174,7 @@ clean_top_5() # 1st 5 lines on Puma local -r L1="Puma starting in single mode..." local -r L2='* Puma version: 6.5.0 ("Sky'"'"'s Version")' - local -r L3='* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux-musl]' + local -r L3='* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f)' # [x86_64-linux-musl] local -r L4="* Min threads: 0" local -r L5="* Max threads: 5" # diff --git a/bin/run_tests.sh b/bin/run_tests.sh index 36bb8aac..3f7d5c3e 100755 --- a/bin/run_tests.sh +++ b/bin/run_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -Eeu export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"