-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest.bats
More file actions
474 lines (384 loc) · 12.3 KB
/
Copy pathtest.bats
File metadata and controls
474 lines (384 loc) · 12.3 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/usr/bin/env bats
setup() {
/bin/rm -rf ~/.bashrc ~/.profile ~/.profilerc* ~/.bashdot another ~/.test ~/.env \
~/.cmd ~/.special ~/.braced ~/.prefix \
/home/circleci/rendered/env.rendered \
/home/circleci/secure/*.rendered \
/tmp/bashdot-pwned-cmd /tmp/bashdot-pwned-bt /tmp/bashdot-pwned-eof /tmp/bashdot-pwned-val \
/tmp/bashdot-empty /tmp/invalid,name /tmp/default /tmp/another \
/tmp/profile_with_invalid1 /tmp/profile_with_invalid2 /tmp/profile_with_invalid3 \
/home/circleci/.dotfiles
}
@test "general help" {
run bashdot
[ "$output" == "Usage: bashdot [dir|install|links|profiles|uninstall|version] OPTIONS" ]
[ $status = 1 ]
}
@test "install help" {
run bashdot install
[ "$output" == "Usage: bashdot install PROFILE1 PROFILE2 ... PROFILEN" ]
[ $status = 1 ]
}
@test "uninstall help" {
run bashdot uninstall
[ "$output" == "Usage: bashdot uninstall PROFILE_DIRECTORY PROFILE" ]
[ $status = 1 ]
}
@test "error invalid profile name" {
run bashdot install test,test
echo $output | grep "Invalid profile name 'test,test'. Profiles must be alpha numeric with only dashes or underscores."
[ $status = 1 ]
}
@test "error profile does not exist" {
mkdir -p /tmp/bashdot-empty
cd /tmp/bashdot-empty
run bashdot install default
echo $output | grep "Profile 'default' directory does not exist."
[ $status = 1 ]
}
@test "error uninstall when no bashdot profiles installed" {
run bashdot uninstall /home/circleci test
echo $output | grep "Config file '$HOME/.bashdot' not found."
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 1 ]
}
@test "error uninstall profiles does not exist" {
cd /home/circleci
bashdot install default
run bashdot uninstall /home/circleci test
echo $output | grep "Profile 'test' not installed from '/home/circleci'."
[ $status = 1 ]
}
@test "error uninstall directory does not exist" {
cd /home/circleci
bashdot install default
run bashdot uninstall /boom default
echo $output | grep "Profile 'default' not installed from '/boom'."
[ $status = 1 ]
}
@test "error file already exists on install" {
touch ~/.bashrc
mkdir -p default
touch default/bashrc
run bashdot install default
echo $output | grep "File '/home/circleci/.bashrc' already exists, exiting."
[ $status = 1 ]
}
@test "error file already in another profile" {
cd /home/circleci
bashdot install default
mkdir -p another
touch another/bashrc
run bashdot install another
[ $status = 1 ]
}
@test "error installing template without variables set" {
cd /home/circleci
unset APP_SECRET_KEY
run bashdot install rendered
echo $output | grep "Variable 'APP_SECRET_KEY' is unset in template '/home/circleci/rendered/env.template'."
[ $status = 1 ]
run test -e /home/circleci/.env
[ $status = 1 ]
run test -e /home/circleci/rendered/env.rendered
[ $status = 1 ]
}
@test "error file already exists on template install" {
touch ~/.env
cd /home/circleci
run env APP_SECRET_KEY=test1234 bashdot install rendered
echo $output | grep "File '/home/circleci/.env' already exists, exiting."
[ $status = 1 ]
}
@test "error installing from invalid current working directory" {
mkdir /tmp/invalid,name
cp -r /home/circleci/default /tmp/invalid,name
cd /tmp/invalid,name
run bashdot install default
[ $status = 1 ]
echo $output | grep "Current working directory '/tmp/invalid,name' has an invalid character. The directory you are in when you install a profile must have alpha numeric characters, with only dashes, dots or underscores."
}
@test "error if profiles directories files contain invalid characters" {
cd /tmp
mkdir -p profile_with_invalid1/invalid\ name
mkdir -p profile_with_invalid2/invalid\\name
mkdir -p profile_with_invalid3/invalid:name
run bashdot install profile_with_invalid1
echo $output |grep "Files in '/tmp/profile_with_invalid1' contain invalid characters."
[ $status = 1 ]
run bashdot install profile_with_invalid2
echo $output |grep "Files in '/tmp/profile_with_invalid2' contain invalid characters."
[ $status = 1 ]
run bashdot install profile_with_invalid3
echo $output |grep "Files in '/tmp/profile_with_invalid3' contain invalid characters."
[ $status = 1 ]
}
@test "install" {
cd /home/circleci
run bashdot install default work
echo $output | grep "Completed installation of all profiles successfully."
[ $status = 0 ]
}
@test "install from directory with leading ." {
cd /home/circleci
mkdir .dotfiles
cp -r default .dotfiles
cp -r work .dotfiles
cd .dotfiles
run bashdot install default work
echo $output | grep "Completed installation of all profiles successfully."
[ $status = 0 ]
}
@test "installing rendered template file" {
cd /home/circleci
run env APP_SECRET_KEY=test1234 bashdot install rendered
echo $output | grep "Completed installation of all profiles successfully."
cat /home/circleci/.env | grep 'export APP_SECRET_KEY=test1234'
run sum /home/circleci/.env
echo $output | grep '58480'
}
@test "template command substitution and backticks are not executed" {
cd /home/circleci
run env SAFE_VAR=ok FOO=one FOOBAR=two BRACED_SECRET=braced123 SPECIAL_VAL=plain \
bashdot install secure
echo $output | grep "Completed installation of all profiles successfully."
[ $status = 0 ]
run test -e /tmp/bashdot-pwned-cmd
[ $status = 1 ]
run test -e /tmp/bashdot-pwned-bt
[ $status = 1 ]
grep -F 'payload=$(touch /tmp/bashdot-pwned-cmd)' /home/circleci/.cmd
grep -F 'ticks=`touch /tmp/bashdot-pwned-bt`' /home/circleci/.cmd
grep -F 'arith=$((1+2))' /home/circleci/.cmd
grep -F 'safe=ok' /home/circleci/.cmd
}
@test "template braced variables are substituted" {
cd /home/circleci
run env SAFE_VAR=ok FOO=one FOOBAR=two BRACED_SECRET=braced123 SPECIAL_VAL=plain \
bashdot install secure
[ $status = 0 ]
grep -F 'export KEY=braced123' /home/circleci/.braced
}
@test "template prefix variables do not clobber longer names" {
cd /home/circleci
run env SAFE_VAR=ok FOO=one FOOBAR=two BRACED_SECRET=braced123 SPECIAL_VAL=plain \
bashdot install secure
[ $status = 0 ]
[ "$(cat /home/circleci/.prefix)" = $'FOO=one\nFOOBAR=two' ]
}
@test "template values are not re-expanded or executed" {
cd /home/circleci
export SAFE_VAR=ok
export FOO=one
export FOOBAR=two
export BRACED_SECRET=braced123
export SPECIAL_VAL=$'line1\nEOF\n$(touch /tmp/bashdot-pwned-eof)\n`touch /tmp/bashdot-pwned-val`\n$HOME'
run bashdot install secure
[ $status = 0 ]
run test -e /tmp/bashdot-pwned-eof
[ $status = 1 ]
run test -e /tmp/bashdot-pwned-val
[ $status = 1 ]
grep -F '$(touch /tmp/bashdot-pwned-eof)' /home/circleci/.special
grep -F '`touch /tmp/bashdot-pwned-val`' /home/circleci/.special
grep -F '$HOME' /home/circleci/.special
grep -F 'after=ok' /home/circleci/.special
}
@test "install suceeds when profile already installed from another directory" {
cd /home/circleci
bashdot install default
cd /tmp
mkdir -p default
touch default/test
run bashdot install default
[ $status = 0 ]
}
@test "install bashdot profiles from another directory" {
cd /home/circleci
bashdot install default work
cd /tmp
mkdir another
touch another/test
run bashdot install another
[ $status = 0 ]
run bashdot profiles
[ "${lines[0]}" == "/home/circleci default" ]
[ "${lines[1]}" == "/home/circleci work" ]
[ "${lines[2]}" == "/tmp another" ]
[ $status = 0 ]
run bashdot dir
[ "${lines[0]}" == "/home/circleci" ]
[ "${lines[1]}" == "/tmp" ]
[ $status = 0 ]
run bashdot links
echo "$output"
[ "${lines[0]}" == "~/.bashrc -> /home/circleci/default/bashrc" ]
[ "${lines[1]}" == "~/.profilerc_work -> /home/circleci/work/profilerc_work" ]
[ "${lines[2]}" == "~/.test -> /tmp/another/test" ]
[ $status = 0 ]
}
@test "install multiple profiles in directories with the same leading prefix" {
cd /home/circleci
bashdot install default work
cd /home/circleci/another_test
bashdot install home
run bashdot profiles
[ "${lines[0]}" == "/home/circleci/another_test home" ]
[ "${lines[1]}" == "/home/circleci default" ]
[ "${lines[2]}" == "/home/circleci work" ]
bashdot uninstall /home/circleci work
run bashdot profiles
[ "${lines[0]}" == "/home/circleci/another_test home" ]
[ "${lines[1]}" == "/home/circleci default" ]
}
@test "validate ignored files not symlinked" {
cd /home/circleci
bashdot install default work home
run test -e /home/circleci/.bashrc
[ $status = 0 ]
run test -e /home/circleci/.profilerc_work
[ $status = 0 ]
run test -e /home/circleci/.profilerc_home
[ $status = 0 ]
run test -e /home/circleci/.README.md
[ $status != 0 ]
run test -e /home/circleci/.CHANGELOG.txt
[ $status != 0 ]
}
@test "re-install" {
cd /home/circleci
bashdot install default work
run bashdot install default work
[ $status = 0 ]
}
@test "list profiles" {
cd /home/circleci
bashdot install default work
run bashdot profiles
[ "${lines[0]}" == "/home/circleci default" ]
[ "${lines[1]}" == "/home/circleci work" ]
[ $status = 0 ]
}
@test "list profiles with only rendered template in home directory" {
cd /home/circleci
run env APP_SECRET_KEY=test1234 bashdot install rendered
run bashdot profiles
[ "${lines[0]}" == "/home/circleci rendered" ]
[ $status = 0 ]
}
@test "links" {
cd /home/circleci
bashdot install default work
run bashdot links
[ "${lines[0]}" == "~/.bashrc -> /home/circleci/default/bashrc" ]
[ "${lines[1]}" == "~/.profilerc_work -> /home/circleci/work/profilerc_work" ]
[ $status = 0 ]
}
@test "dir" {
cd /home/circleci
bashdot install default work
run bashdot dir
[ "${lines[0]}" == "/home/circleci" ]
[ $status = 0 ]
}
@test "profiles when no dotfiles installed" {
run bashdot profiles
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 0 ]
}
@test "dir no dotfiles installed" {
run bashdot dir
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 0 ]
}
@test "version" {
version=$(grep ^VERSION /usr/bin/bashdot |cut -d\= -f2)
run bashdot version
[ "$output" == "$version" ]
[ $status = 0 ]
}
@test "profilerc is sourced" {
cd /home/circleci
bashdot install default work
. ~/.bashrc
[ "$HOME_VAR" == "" ]
[ "$WORK_VAR" == "123" ]
bashdot install home
. ~/.bashrc
[ "$HOME_VAR" == "abc" ]
}
@test "uninstall" {
cd /home/circleci
bashdot install default work
run bashdot dir
[ "$output" == "/home/circleci" ]
[ $status = 0 ]
run bashdot uninstall /home/circleci default
[ $status = 0 ]
run bashdot uninstall /home/circleci work
[ $status = 0 ]
run bashdot profiles
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 0 ]
run bashdot dir
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 0 ]
}
@test "uninstall multiple directories" {
cd /home/circleci
bashdot install default work
cd /tmp
mkdir -p another
touch another/test
bashdot install another
run bashdot dir
[ "${lines[0]}" == "/home/circleci" ]
[ "${lines[1]}" == "/tmp" ]
[ $status = 0 ]
run bashdot uninstall /home/circleci work
[ $status = 0 ]
run bashdot profiles
[ "${lines[0]}" == "/home/circleci default" ]
[ "${lines[1]}" == "/tmp another" ]
[ $status = 0 ]
run bashdot dir
[ "${lines[0]}" == "/home/circleci" ]
[ "${lines[1]}" == "/tmp" ]
[ $status = 0 ]
run bashdot uninstall /tmp another
[ $status = 0 ]
run bashdot profiles
[ "${lines[0]}" == "/home/circleci default" ]
[ "${lines[1]}" == "" ]
[ $status = 0 ]
run bashdot dir
[ "${lines[0]}" == "/home/circleci" ]
[ $status = 0 ]
run bashdot uninstall /home/circleci default
[ $status = 0 ]
run bashdot profiles
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 0 ]
run bashdot dir
echo $output | grep "No dotfiles installed by bashdot."
[ $status = 0 ]
run test -f ~/.bashdot
[ $status = 1 ]
}
@test "uninstall rendered file" {
run test -f /home/circleci/.env
[ $status = 1 ]
run test -f /home/circleci/rendered/env.rendered
[ $status = 1 ]
cd /home/circleci
env APP_SECRET_KEY=test1234 bashdot install rendered
run test -f /home/circleci/.env
[ $status = 0 ]
run test -f /home/circleci/rendered/env.rendered
[ $status = 0 ]
bashdot uninstall /home/circleci rendered
run test -f /home/circleci/.env
[ $status = 1 ]
run test -f /home/circleci/rendered/env.rendered
[ $status = 1 ]
}