1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6
#
# test profile dynvariables and included dynvariables
# returns 1 in case of error
#
## start-cookie
set -eu -o errtrace -o pipefail
cur=$(cd "$(dirname "${0}")" && pwd)
ddpath="${cur}/../"
PPATH="{PYTHONPATH:-}"
export PYTHONPATH="${ddpath}:${PPATH}"
altbin="python3 -m dotdrop.dotdrop"
if hash coverage 2>/dev/null; then
mkdir -p coverages/
altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop"
fi
bin="${DT_BIN:-${altbin}}"
# shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
## end-cookie
################################################################
# this is the test
################################################################
# the dotfile source
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles
# the dotfile destination
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
clear_on_exit "${tmps}"
clear_on_exit "${tmpd}"
# create the config file
cfg="${tmps}/config.yaml"
cfg2="${tmps}/sub.yaml"
cat > "${cfg}" << _EOF
config:
dotpath: dotfiles
import_configs:
- sub.yaml
variables:
mainvar: 'not-that'
subvar: 'not-that-either'
dynvariables:
maindyn: 'echo wont-work'
subdyn: 'echo wont-work-either'
dotfiles:
profiles:
profile_1:
include:
- subprofile
dynvariables:
maindyn: 'echo maindyncontent'
variables:
mainvar: 'maincontent'
profile_2:
include:
- subignore
_EOF
#cat ${cfg}
cat > "${cfg2}" << _EOF
config:
dotfiles:
f_abc:
dst: ${tmpd}/abc
src: abc
f_def:
dst: ${tmpd}/def
src: def
f_ghi:
dst: '${tmpd}/{{@@ ghi @@}}'
src: ghi
variables:
mainvar: 'bad0'
subvar: 'bad1'
dynvariables:
maindyn: 'echo bad2'
subdyn: 'echo bad3'
profiles:
subprofile:
dotfiles:
- f_abc
- f_ghi
dynvariables:
subdyn: 'echo subdyncontent'
ghi: 'echo ghi'
variables:
subvar: 'subcontent'
subignore:
dotfiles:
- f_def
_EOF
#cat ${cfg2}
# create the dotfile
echo "start" > "${tmps}"/dotfiles/abc
echo "{{@@ mainvar @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ maindyn @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ subdyn @@}}" >> "${tmps}"/dotfiles/abc
echo "{{@@ subvar @@}}" >> "${tmps}"/dotfiles/abc
echo "end" >> "${tmps}"/dotfiles/abc
#cat ${tmps}/dotfiles/abc
echo "ghi content" > "${tmps}"/dotfiles/ghi
# install
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p profile_1 --verbose
# check dotfile exists
[ ! -e "${tmpd}"/abc ] && exit 1
grep 'maincontent' "${tmpd}"/abc >/dev/null || (echo "variables 1 not resolved" && exit 1)
grep 'maindyncontent' "${tmpd}"/abc >/dev/null || (echo "dynvariables 1 not resolved" && exit 1)
grep 'subcontent' "${tmpd}"/abc >/dev/null || (echo "variables 2 not resolved" && exit 1)
grep 'subdyncontent' "${tmpd}"/abc >/dev/null || (echo "dynvariables 2 not resolved" && exit 1)
#cat ${tmpd}/abc
[ ! -e "${tmpd}"/ghi ] && exit 1
echo "OK"
exit 0
|