bash3boilerplate/test/scenario/templater/run.sh
Manuel Streuhofer f57e37eb68 fix templater.sh and associated test
templater.sh now escapes the delimiter it uses for its sed magic within
the environment variable content.

the associated test uses a properly cleaned up temporary file instead of
explicitly rm-ing its own mess.
2018-01-23 22:02:57 +01:00

37 lines
1.1 KiB
Bash

#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename "${__file}" .sh)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
__templaterTmpFile=$(mktemp "${TMPDIR:-/tmp}/${__base}.XXXXXX")
function cleanup_before_exit () { rm "${__templaterTmpFile:?}"; }
trap cleanup_before_exit EXIT
echo "--"
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./app.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"
echo "--"
export TARGET_HOST="127.0.0.1"
# shellcheck source=src/templater.sh
source "${__root}/src/templater.sh"
templater ./app.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"
echo "--"
env ALLOW_REMAINDERS="1" TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"
echo "--"
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg "${__templaterTmpFile}"
cat "${__templaterTmpFile}"