File: remove.sh

package info (click to toggle)
dotdrop 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: sh: 13,401; python: 8,186; makefile: 3
file content (161 lines) | stat: -rwxr-xr-x 3,853 bytes parent folder | download | duplicates (2)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2019, deadc0de6
#
# test remove
# 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
################################################################

# dotdrop directory
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
mkdir -p "${tmps}"/dotfiles
# the dotfile to be imported
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)

clear_on_exit "${tmps}"
clear_on_exit "${tmpd}"

# create the config file
cfg="${tmps}/config.yaml"
cat > "${cfg}" << _EOF
config:
  backup: true
  create: true
  dotpath: dotfiles
dotfiles:
  f_abc:
    dst: ${tmpd}/abc
    src: abc
  f_def:
    dst: ${tmpd}/def
    src: def
  f_last:
    dst: ${tmpd}/last
    src: last
profiles:
  p1:
    dotfiles:
    - f_abc
    - f_def
  p2:
    dotfiles:
    - f_def
  last:
    dotfiles:
    - f_last
_EOF
cfgbak="${tmps}/config.yaml.bak"
cp "${cfg}" "${cfgbak}"

# create the dotfile
echo "abc" > "${tmps}"/dotfiles/abc
echo "abc" > "${tmpd}"/abc

echo "def" > "${tmps}"/dotfiles/def
echo "def" > "${tmpd}"/def

# remove with bad profile
cd "${ddpath}" | ${bin} remove -f -k -p empty -c "${cfg}" f_abc -V
[ ! -e "${tmps}"/dotfiles/abc ] && echo "dotfile in dotpath deleted" && exit 1
[ ! -e "${tmpd}"/abc ] && echo "source dotfile deleted" && exit 1
[ ! -e "${tmps}"/dotfiles/def ] && echo "dotfile in dotpath deleted" && exit 1
[ ! -e "${tmpd}"/def ] && echo "source dotfile deleted" && exit 1
# ensure config not altered
diff "${cfg}" "${cfgbak}"

# remove by key
echo "[+] remove f_abc by key"
cd "${ddpath}" | ${bin} remove -p p1 -f -k -c "${cfg}" f_abc -V
cat "${cfg}"
echo "[+] remove f_def by key"
cd "${ddpath}" | ${bin} remove -p p2 -f -k -c "${cfg}" f_def -V
cat "${cfg}"

# checks
[ -e "${tmps}"/dotfiles/abc ] && echo "dotfile in dotpath not deleted" && exit 1
[ ! -e "${tmpd}"/abc ] && echo "source dotfile deleted" && exit 1

[ -e "${tmps}"/dotfiles/def ] && echo "dotfile in dotpath not deleted" && exit 1
[ ! -e "${tmpd}"/def ] && echo "source dotfile deleted" && exit 1

echo "[+] ========="

# create the config file
cfg="${tmps}/config.yaml"
cat > "${cfg}" << _EOF
config:
  backup: true
  create: true
  dotpath: dotfiles
dotfiles:
  f_abc:
    dst: ${tmpd}/abc
    src: abc
  f_def:
    dst: ${tmpd}/def
    src: def
  f_last:
    dst: ${tmpd}/last
    src: last
profiles:
  p1:
    dotfiles:
    - f_abc
    - f_def
  p2:
    dotfiles:
    - f_def
  last:
    dotfiles:
    - f_last
_EOF
cat "${cfg}"

# create the dotfile
echo "abc" > "${tmps}"/dotfiles/abc
echo "abc" > "${tmpd}"/abc

echo "def" > "${tmps}"/dotfiles/def
echo "def" > "${tmpd}"/def

# remove by key
echo "[+] remove f_abc by path"
cd "${ddpath}" | ${bin} remove -p p1 -f -c "${cfg}" "${tmpd}"/abc -V
cat "${cfg}"
echo "[+] remove f_def by path"
cd "${ddpath}" | ${bin} remove -p p2 -f -c "${cfg}" "${tmpd}"/def -V
cat "${cfg}"

# checks
[ -e "${tmps}"/dotfiles/abc ] && echo "(2) dotfile in dotpath not deleted" && exit 1
[ ! -e "${tmpd}"/abc ] && echo "(2) source dotfile deleted" && exit 1

[ -e "${tmps}"/dotfiles/def ] && echo "(2) dotfile in dotpath not deleted" && exit 1
[ ! -e "${tmpd}"/def ] && echo "(2) source dotfile deleted" && exit 1


cat "${cfg}"

echo "OK"
exit 0