#!/bin/bash # Does compose still find its file when CFG__COMPOSE_FILE is out of scope? # # scripts/dev/lp-compose-file-test # # dockerComposeUp/Down derive compose_file from $compose_setup, which # setupBasicScanVariables reads from CFG__COMPOSE_FILE. That variable is # only set once the app's config has been sourced, and it is not always — a # restore wipes and re-creates the app folder around those calls. # # setupBasicScanVariables already falls back to the standard file for that case. # The two compose functions did not: with compose_setup empty, neither branch # ran, compose_file stayed UNSET, and the guard # # [ ! -f "$(appDir "$app")/$compose_file" ] # # then tested the app DIRECTORY, which is never a regular file. So the app was # reported as having no compose file and quietly not started — visible only as # "Unable to find the compose file", with the restore itself reporting success. REPO="$(cd "$(dirname "$0")/../.." && pwd)" BASE="$(mktemp -d "${TMPDIR:-/tmp}/lp-compose-test-XXXXXX")" trap 'rm -rf "$BASE"' EXIT fail=0 chk(){ if [[ "$2" == "$3" ]]; then echo " ok $1"; else echo " FAIL $1: got '$2' want '$3'"; fail=1; fi; } mkdir -p "$BASE/myapp" : > "$BASE/myapp/docker-compose.yml" run() { # run -> prints what the guard decided local setup="$1" bash -c ' OS_TYPE=Ubuntu appDir(){ printf "%s/%s" "'"$BASE"'" "$1"; } setupBasicScanVariables(){ :; } isHeader(){ :; }; isError(){ :; }; isSuccessful(){ :; }; checkSuccess(){ :; } isNotice(){ echo "NOTICE: $*"; } # Everything past the guard is docker; stop there. dockerCommandRunInstallUser(){ echo "REACHED_DOCKER"; } runFileOp(){ echo "REACHED_DOCKER"; } compose_setup="'"$setup"'" source "'"$REPO"'/scripts/docker/app/compose/down_app.sh" dockerComposeDown myapp 2>/dev/null ' 2>/dev/null } echo "--- compose_setup=default (the normal path) ---" out=$(run default) chk "does not report a missing file" "$(grep -c 'Unable to find' <<< "$out")" "0" echo "--- compose_setup empty (config not sourced — the restore case) ---" out=$(run "") chk "does not report a missing file" "$(grep -c 'Unable to find' <<< "$out")" "0" echo "--- and it genuinely reports a file that is absent ---" rm -f "$BASE/myapp/docker-compose.yml" out=$(run "") chk "reports the missing file" "$(grep -c 'Unable to find' <<< "$out")" "1" echo "" if (( fail )); then echo "FAILED"; exit 1; fi echo "All compose-file checks passed."