From 87b70053c89e866ea0c94ae527ff9cd94cefe7fb Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 14 Nov 2020 15:01:56 +0100 Subject: [PATCH] improve tests --- tests-ng/chmod-compare.sh | 3 +-- tests-ng/chmod-import.sh | 19 +++++++++------- tests-ng/chmod-install.sh | 47 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/tests-ng/chmod-compare.sh b/tests-ng/chmod-compare.sh index c8e77e2..c92be03 100755 --- a/tests-ng/chmod-compare.sh +++ b/tests-ng/chmod-compare.sh @@ -94,7 +94,7 @@ profiles: _EOF #cat ${cfg} -# import without --preserve-mode +# import for i in ${toimport}; do cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 ${i} done @@ -111,7 +111,6 @@ chmod 700 ${flink} set +e cnt=`cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 2>&1 | grep 'modes differ' | wc -l` set -e - [ "${cnt}" != "5" ] && echo "compare modes failed" && exit 1 ## CLEANING diff --git a/tests-ng/chmod-import.sh b/tests-ng/chmod-import.sh index 054a0c0..6d1a5da 100755 --- a/tests-ng/chmod-import.sh +++ b/tests-ng/chmod-import.sh @@ -67,7 +67,7 @@ mkdir -p ${tmps}/dotfiles tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` #echo "dotfile destination: ${tmpd}" -# create the dotfile +# create the dotfiles dnormal="${tmpd}/dir_normal" mkdir -p ${dnormal} echo "dir_normal/f1" > ${dnormal}/file1 @@ -120,8 +120,8 @@ cat ${cfg} cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep chmod | wc -l` -[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted" && exit 1 +cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (1)" && exit 1 ## with link cat > ${cfg} << _EOF @@ -138,7 +138,6 @@ rm -rf ${tmps}/dotfiles mkdir -p ${tmps}/dotfiles # import without --preserve-mode and link - for i in ${toimport}; do cd ${ddpath} | ${bin} import -c ${cfg} -l link -f -p p1 -V ${i} done @@ -149,8 +148,12 @@ cat ${cfg} cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep chmod | wc -l` -[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted" && exit 1 +cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` +[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (2)" && exit 1 + +tot=`echo ${toimport} | wc -w` +cnt=`cat ${cfg} | grep 'link: link' | wc -l` +[ "${cnt}" != "${tot}" ] && echo "not all link inserted" && exit 1 ## --preserve-mode cat > ${cfg} << _EOF @@ -178,8 +181,8 @@ cat ${cfg} cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep chmod | wc -l` -[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted" && exit 1 +cnt=`cat ${cfg} | grep "chmod: " | wc -l` +[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (3)" && exit 1 ## import normal cat > ${cfg} << _EOF diff --git a/tests-ng/chmod-install.sh b/tests-ng/chmod-install.sh index 05ff2a8..01ed80a 100755 --- a/tests-ng/chmod-install.sh +++ b/tests-ng/chmod-install.sh @@ -58,6 +58,22 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" # this is the test ################################################################ +get_file_mode() +{ + u=`umask` + u=`echo ${u} | sed 's/^0*//'` + v=$((666 - u)) + echo "${v}" +} + +get_dir_mode() +{ + u=`umask` + u=`echo ${u} | sed 's/^0*//'` + v=$((777 - u)) + echo "${v}" +} + # the dotfile source tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` mkdir -p ${tmps}/dotfiles @@ -98,6 +114,8 @@ echo '{{@@ profile @@}}' > ${tmps}/dotfiles/symlinktemplate mkdir -p ${tmps}/dotfiles/symlinktemplatedir echo "{{@@ profile @@}}" > ${tmps}/dotfiles/symlinktemplatedir/t +echo 'nomode' > ${tmps}/dotfiles/nomode + cat > ${cfg} << _EOF config: backup: true @@ -145,6 +163,9 @@ dotfiles: dst: ${tmpd}/symlinktemplatedir chmod: 777 link: link + f_nomode: + src: nomode + dst: ${tmpd}/nomode profiles: p1: dotfiles: @@ -157,12 +178,14 @@ profiles: - d_linkchildren - f_symlinktemplate - d_symlinktemplatedir + - f_nomode p2: dotfiles: - f_exists - f_existslink - d_linkchildren - f_symlinktemplate + - f_nomode _EOF #cat ${cfg} @@ -182,6 +205,8 @@ has_rights "${tmpd}/linkchildren/f1" "644" has_rights "${tmpd}/linkchildren/d1" "755" has_rights "${tmpd}/linkchildren/d1/f2" "644" has_rights "${tmpd}/symlinktemplate" "777" +m=`get_file_mode` +has_rights "${tmpd}/nomode" "${m}" grep 'p1' ${tmpd}/symlinktemplate grep 'p1' ${tmpd}/symlinktemplatedir/t @@ -207,6 +232,28 @@ has_rights "${tmpd}/linkchildren/f1" "644" has_rights "${tmpd}/linkchildren/d1" "755" has_rights "${tmpd}/linkchildren/d1/f2" "644" has_rights "${tmpd}/symlinktemplate" "777" +m=`get_file_mode` +has_rights "${tmpd}/nomode" "${m}" + +## no user confirmation expected +## same mode +echo "same mode" +echo "nomode" > ${tmps}/dotfiles/nomode +chmod 600 ${tmps}/dotfiles/nomode +echo "nomode" > ${tmpd}/nomode +chmod 600 ${tmpd}/nomode +cd ${ddpath} | ${bin} install -c ${cfg} -p p2 -V f_nomode +has_rights "${tmpd}/nomode" "600" + +## user confirmation expected +## different mode +echo "different mode" +echo "nomode" > ${tmps}/dotfiles/nomode +chmod 600 ${tmps}/dotfiles/nomode +echo "nomode" > ${tmpd}/nomode +chmod 700 ${tmpd}/nomode +cd ${ddpath} | printf 'y\n' | ${bin} install -c ${cfg} -p p2 -V f_nomode +has_rights "${tmpd}/nomode" "600" ## CLEANING rm -rf ${tmps} ${tmpd}