#!/usr/bin/env bash set -u -o pipefail TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" test_dir="$(mktemp -d)" trap 'rm -rf "$test_dir"' EXIT TAPM_CONFIG_FILE="${test_dir}/etc/config.env" TAPM_CONFIG_TEST_STDIN=1 source "${TEST_ROOT}/inc/runtime-config.inc" if ! printf '%s\n%s\n' \ 'https://tapm.example.com' \ 'git.example.com' | TAPM_ENSURE_RUNTIME_CONFIG >/dev/null; then printf 'FAIL: configuration wizard failed\n' >&2 exit 1 fi expected=$'TAPM_BROKER_URL=https://tapm.example.com\nGITEA_DOMAIN=git.example.com' actual="$(cat "$TAPM_CONFIG_FILE")" if [[ "$actual" != "$expected" ]]; then printf 'FAIL: unexpected configuration contents\n' >&2 exit 1 fi if stat -c '%a' "$TAPM_CONFIG_FILE" >/dev/null 2>&1; then config_mode="$(stat -c '%a' "$TAPM_CONFIG_FILE")" else config_mode="$(stat -f '%Lp' "$TAPM_CONFIG_FILE")" fi if [[ "$config_mode" != 600 ]]; then printf 'FAIL: configuration mode is not 600\n' >&2 exit 1 fi unset TAPM_BROKER_URL GITEA_DOMAIN GITEA_URL TAPM_LOAD_RUNTIME_CONFIG if [[ "$TAPM_BROKER_URL" != 'https://tapm.example.com' || "$GITEA_DOMAIN" != 'git.example.com' || "$GITEA_URL" != 'https://git.example.com' ]]; then printf 'FAIL: saved configuration did not reload\n' >&2 exit 1 fi printf 'PASS: runtime configuration wizard\n'