-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdotfiles_test.sh
executable file
·562 lines (424 loc) · 18.1 KB
/
dotfiles_test.sh
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
#!/bin/bash
# Title Dotfiles tests
# Author Zachi Nachshon <[email protected]>
# Supported OS Linux & macOS
# Description Run dotfiles tests suite
#==============================================================================
DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH=$(dirname "${BASH_SOURCE[0]}")
# TODO: Need to run in a container with bash installed
source "${DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH}/external/shell_scripts_lib/logger.sh"
source "${DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH}/external/shell_scripts_lib/shell.sh"
source "${DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH}/external/shell_scripts_lib/test_lib/init.sh"
source "${DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH}/external/shell_scripts_lib/test_lib/assert.sh"
source "${DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH}/external/shell_scripts_lib/test_lib/assert.sh"
source "${DOTFILES_TEST_CURRENT_FOLDER_ABS_PATH}/external/shell_scripts_lib/test_lib/test_logs.sh"
TEST_DATA_DOTFILES_REPO_PATH="${PWD}/test_data/dotfiles_repo"
TEST_DATA_DOTFILES_CLI_REPO_PATH="${PWD}"
set_test_repository_paths() {
export DOTFILES_REPO_LOCAL_PATH="${TEST_DATA_DOTFILES_REPO_PATH}"
export DOTFILES_CLI_INSTALL_PATH="${TEST_DATA_DOTFILES_CLI_REPO_PATH}"
}
before_test() {
test_set_up
TEST_name=$1
TEST_passed="True"
set_test_repository_paths
test_log_print_test_name "${TEST_name}"
}
after_test() {
test_tear_down
}
test_dotfiles_version() {
before_test "test_dotfiles_version"
# Given I read the version from version.txt file
local expected_version=$(cat ./resources/version.txt)
# And I check the dotfiles CLI version
./dotfiles.sh version >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect the version to be equal
assert_expect_log "${expected_version}"
after_test
}
test_dotfiles_sync_all() {
before_test "test_dotfiles_sync_all"
# Given I prepare the expected HOME folder symlinks
local home_link_gitigonre="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.gitignore_global ${HOME}/.gitignore_global"
local home_link_vimrc="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.vimrc ${HOME}/.vimrc"
local home_link_gitconfig="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.gitconfig ${HOME}/.gitconfig"
local home_link_dummy=""
local shell_link_dummy=""
if shell_is_zsh; then
home_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.dummy.zsh ${HOME}/.dummy.zsh"
shell_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/shell/.zshrc ${HOME}/.zshrc"
elif shell_is_bash; then
home_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.dummy.bash ${HOME}/.dummy.bash"
shell_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/shell/.bashrc ${HOME}/.bashrc"
fi
# And I sync all home and shell files
./dotfiles.sh sync all --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all symlinks to exists
assert_expect_log "${home_link_gitigonre}"
assert_expect_log "${home_link_dummy}"
assert_expect_log "${home_link_vimrc}"
assert_expect_log "${home_link_gitconfig}"
assert_expect_log "${shell_link_dummy}"
after_test
}
test_dotfiles_sync_home() {
before_test "test_dotfiles_sync_home"
# Given I prepare the expected HOME folder symlinks
local home_link_gitigonre="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.gitignore_global ${HOME}/.gitignore_global"
local home_link_vimrc="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.vimrc ${HOME}/.vimrc"
local home_link_gitconfig="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.gitconfig ${HOME}/.gitconfig"
local home_link_dummy=""
if shell_is_zsh; then
home_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.dummy.zsh ${HOME}/.dummy.zsh"
elif shell_is_bash; then
home_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/home/.dummy.bash ${HOME}/.dummy.bash"
fi
# And I sync home files
./dotfiles.sh sync home --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect home symlinks to exists
assert_expect_log "${home_link_gitigonre}"
assert_expect_log "${home_link_dummy}"
assert_expect_log "${home_link_vimrc}"
assert_expect_log "${home_link_gitconfig}"
after_test
}
test_dotfiles_sync_shell() {
before_test "test_dotfiles_sync_shell"
# Given I prepare the expected HOME folder symlinks
local shell_link_dummy=""
if shell_is_zsh; then
shell_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/shell/.zshrc ${HOME}/.zshrc"
elif shell_is_bash; then
shell_link_dummy="${TEST_DATA_DOTFILES_REPO_PATH}/dotfiles/shell/.bashrc ${HOME}/.bashrc"
fi
# And I sync shell files
./dotfiles.sh sync shell --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect shell symlinks to exists
assert_expect_log "${shell_link_dummy}"
after_test
}
test_dotfiles_unsync_all() {
before_test "test_dotfiles_unsync_all"
# Given I prepare the expected files to unlink
local home_unlink_gitigonre="unlink ${HOME}/.gitignore_global"
local home_unlink_vimrc="unlink ${HOME}/.vimrc"
local home_unlink_gitconfig="unlink ${HOME}/.gitconfig"
local home_link_dummy=""
local shell_link_dummy=""
if shell_is_zsh; then
home_unlink_dummy="unlink ${HOME}/.dummy.zsh"
shell_link_dummy="unlink ${HOME}/.zshrc"
elif shell_is_bash; then
home_unlink_dummy="unlink ${HOME}/.dummy.bash"
shell_link_dummy="unlink ${HOME}/.bashrc"
fi
# And I unsync all home and shell files
./dotfiles.sh unsync all --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all symlinks to get unlinked
assert_expect_log "${home_unlink_gitigonre}"
assert_expect_log "${home_unlink_dummy}"
assert_expect_log "${home_unlink_vimrc}"
assert_expect_log "${home_unlink_gitconfig}"
assert_expect_log "${shell_link_dummy}"
after_test
}
test_dotfiles_unsync_home() {
before_test "test_dotfiles_unsync_home"
# Given I prepare the expected files to unlink
local home_unlink_gitigonre="unlink ${HOME}/.gitignore_global"
local home_unlink_vimrc="unlink ${HOME}/.vimrc"
local home_unlink_gitconfig="unlink ${HOME}/.gitconfig"
local home_link_dummy=""
if shell_is_zsh; then
home_unlink_dummy="unlink ${HOME}/.dummy.zsh"
elif shell_is_bash; then
home_unlink_dummy="unlink ${HOME}/.dummy.bash"
fi
# And I unsync home files
./dotfiles.sh unsync home --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect home symlinks to get unlinked
assert_expect_log "${home_unlink_gitigonre}"
assert_expect_log "${home_unlink_dummy}"
assert_expect_log "${home_unlink_vimrc}"
assert_expect_log "${home_unlink_gitconfig}"
after_test
}
test_dotfiles_unsync_shell() {
before_test "test_dotfiles_unsync_shell"
# Given I prepare the expected files to unlink
local shell_link_dummy=""
if shell_is_zsh; then
shell_link_dummy="unlink ${HOME}/.zshrc"
elif shell_is_bash; then
shell_link_dummy="unlink ${HOME}/.bashrc"
fi
# And I unsync shell files
./dotfiles.sh unsync shell --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect shell symlinks to get unlinked
assert_expect_log "${shell_link_dummy}"
after_test
}
test_brew_prerequisites() {
before_test "test_brew_prerequisites"
# Given I prepare the expected brew prerequisites
local brew_tap_casks_versions="brew tap homebrew/cask-versions"
local brew_tap_cask_fonts="brew tap homebrew/cask-fonts"
local brew_tap_cask_drivers="brew tap homebrew/cask-drivers"
local brew_install_tap_1="brew tap dummy-tap-1"
local brew_install_tap_2="brew tap dummy-tap-2"
local brew_outdated="brew outdated"
local brew_update="brew update"
local brew_upgrade="brew upgrade"
# And I run a brew command
./dotfiles.sh brew packages --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all prerequisites to run
assert_expect_log "${brew_tap_casks_versions}"
assert_expect_log "${brew_tap_cask_fonts}"
assert_expect_log "${brew_tap_cask_drivers}"
assert_expect_log "${brew_install_tap_1}"
assert_expect_log "${brew_install_tap_2}"
assert_expect_log "${brew_outdated}"
assert_expect_log "${brew_update}"
assert_expect_log "${brew_upgrade}"
after_test
}
test_brew_pacakges() {
before_test "test_brew_pacakges"
# Given I prepare the expected brew packages to install
local brew_install_pacakges="brew install dummy-package-1 dummy-package-2"
# And I run a brew packages install command
./dotfiles.sh brew packages --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all brew packages to get installed
assert_expect_log "${brew_install_pacakges}"
after_test
}
test_brew_casks() {
before_test "test_brew_casks"
# Given I prepare the expected brew casks to install
local brew_install_cask_1="brew install --cask dummy-cask-1"
local brew_install_cask_2="brew install --cask dummy-cask-2"
# And I run a brew casks install command
./dotfiles.sh brew casks --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all brew casks to get installed
assert_expect_log "${brew_install_cask_1}"
assert_expect_log "${brew_install_cask_2}"
after_test
}
test_brew_drivers() {
before_test "test_brew_drivers"
# Given I prepare the expected brew drivers to install
local brew_install_driver_1="brew install --cask dummy-driver-1"
local brew_install_driver_2="brew install --cask dummy-driver-2"
# And I run a brew drivers install command
./dotfiles.sh brew drivers --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all brew drivers to get installed
assert_expect_log "${brew_install_driver_1}"
assert_expect_log "${brew_install_driver_2}"
after_test
}
test_brew_services() {
before_test "test_brew_services"
# Given I prepare the expected brew services to install and start
local brew_install_service_1="brew install dummy-service-1"
local brew_start_service_1="brew services start dummy-service-1"
local brew_install_service_2="brew install dummy-service-2"
local brew_start_service_2="brew services start dummy-service-2"
# And I run a brew services install command
./dotfiles.sh brew services --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all brew services to get installed and started
assert_expect_log "${brew_install_service_1}"
assert_expect_log "${brew_start_service_1}"
assert_expect_log "${brew_install_service_2}"
assert_expect_log "${brew_start_service_2}"
after_test
}
test_brew_all() {
before_test "test_brew_all"
# Given I prepare the expected brew packages to install
local brew_install_pacakges="brew install dummy-package-1 dummy-package-2"
# And I prepare the expected brew casks to install
local brew_install_cask_1="brew install --cask dummy-cask-1"
local brew_install_cask_2="brew install --cask dummy-cask-2"
# And I prepare the expected brew drivers to install
local brew_install_driver_1="brew install --cask dummy-driver-1"
local brew_install_driver_2="brew install --cask dummy-driver-2"
# And I prepare the expected brew services to install and start
local brew_install_service_1="brew install dummy-service-1"
local brew_start_service_1="brew services start dummy-service-1"
local brew_install_service_2="brew install dummy-service-2"
local brew_start_service_2="brew services start dummy-service-2"
# And I run a brew services install command
./dotfiles.sh brew all --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect all brew packages to get installed
assert_expect_log "${brew_install_pacakges}"
# Then I expect all brew casks to get installed
assert_expect_log "${brew_install_cask_1}"
assert_expect_log "${brew_install_cask_2}"
# Then I expect all brew drivers to get installed
assert_expect_log "${brew_install_driver_1}"
assert_expect_log "${brew_install_driver_2}"
# Then I expect all brew services to get installed and started
assert_expect_log "${brew_install_service_1}"
assert_expect_log "${brew_start_service_1}"
assert_expect_log "${brew_install_service_2}"
assert_expect_log "${brew_start_service_2}"
after_test
}
test_os_mac() {
before_test "test_os_mac"
# Given I prepare the expected mac OS scripts to install
local os_install_script_1="eval '${TEST_DATA_DOTFILES_REPO_PATH}/os/mac/dummy_1.sh'"
local os_install_script_2="eval '${TEST_DATA_DOTFILES_REPO_PATH}/os/mac/dummy_2.sh'"
# And I run a mac os scripts install command
./dotfiles.sh os mac --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect mac os scripts to get evaluated
assert_expect_log "${os_install_script_1}"
assert_expect_log "${os_install_script_2}"
after_test
}
test_os_linux() {
before_test "test_os_linux"
# Given I prepare the expected linux OS scripts to install
local os_install_script_1="eval '${TEST_DATA_DOTFILES_REPO_PATH}/os/linux/dummy_1.sh'"
local os_install_script_2="eval '${TEST_DATA_DOTFILES_REPO_PATH}/os/linux/dummy_2.sh'"
# And I run a linux os scripts install command
./dotfiles.sh os linux --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect linux os scripts to get evaluated
assert_expect_log "${os_install_script_1}"
assert_expect_log "${os_install_script_2}"
after_test
}
test_plugins_zsh() {
before_test "test_plugins_zsh"
# Given I prepare the expected zsh plugins scripts to install
local plugins_zsh_script_1="eval '${TEST_DATA_DOTFILES_REPO_PATH}/plugins/zsh/dummy_1.sh'"
local plugins_zsh_script_2="eval '${TEST_DATA_DOTFILES_REPO_PATH}/plugins/zsh/dummy_2.sh'"
# And I run a zsh plugins install command
./dotfiles.sh plugins zsh --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect zsh plugins scripts to get evaluated
assert_expect_log "${plugins_zsh_script_1}"
assert_expect_log "${plugins_zsh_script_2}"
after_test
}
test_plugins_bash() {
before_test "test_plugins_bash"
# Given I prepare the expected zsh plugins scripts to install
local plugins_bash_script_1="eval '${TEST_DATA_DOTFILES_REPO_PATH}/plugins/bash/dummy_1.sh'"
local plugins_bash_script_2="eval '${TEST_DATA_DOTFILES_REPO_PATH}/plugins/bash/dummy_2.sh'"
# And I run a bash plugins install command
./dotfiles.sh plugins bash --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect bash plugins scripts to get evaluated
assert_expect_log "${plugins_bash_script_1}"
assert_expect_log "${plugins_bash_script_2}"
after_test
}
test_plugins_bash() {
before_test "test_plugins_bash"
# Given I prepare the expected zsh plugins scripts to install
local plugins_bash_script_1="eval '${TEST_DATA_DOTFILES_REPO_PATH}/plugins/bash/dummy_1.sh'"
local plugins_bash_script_2="eval '${TEST_DATA_DOTFILES_REPO_PATH}/plugins/bash/dummy_2.sh'"
# And I run a bash plugins install command
./dotfiles.sh plugins bash --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect bash plugins scripts to get evaluated
assert_expect_log "${plugins_bash_script_1}"
assert_expect_log "${plugins_bash_script_2}"
after_test
}
test_reload_shell_session() {
before_test "test_reload_shell_session"
# Given I prepare the expected reload output
local reload_output="(export DOTFILES_CLI_SILENT_OPTION=False && \
export DOTFILES_CLI_INSTALL_PATH=${DOTFILES_CLI_INSTALL_PATH} && exec $SHELL)"
# And I run a reload command
./dotfiles.sh reload --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect the reload output to exist
assert_expect_log "${reload_output}"
after_test
}
test_change_dir_to_dotfiles_repo() {
before_test "test_change_dir_to_dotfiles_repo"
# Given I prepare the expected chagne dir output
local change_dir_output="(export DOTFILES_CLI_SILENT_OPTION=True && $SHELL)"
# And I run a repo command
./dotfiles.sh repo --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect the repo change dir output to exist
assert_expect_log "${change_dir_output}"
after_test
}
test_link_dotfiles_repository_default_branch() {
before_test "test_link_dotfiles_repository_default_branch"
local repo_url="https://test.repo.com"
local repo_branch="master"
# Given I prepare the link dotfiles repo outputs
local prev_dotfile_removal="rm -rf ${DOTFILES_REPO_LOCAL_PATH}"
local git_clone_command_custom_branch="git -C ${HOME}/.config clone --branch ${repo_branch} --single-branch ${repo_url} --quiet"
# And I run a link dotfiles repository command
./dotfiles.sh link "${repo_url}" --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect the repo change dir output to exist
assert_expect_log "${prev_dotfile_removal}"
assert_expect_log "${git_clone_command_custom_branch}"
after_test
}
test_link_dotfiles_repository_custom_branch() {
before_test "test_link_dotfiles_repository_custom_branch"
local repo_url="https://test.repo.com"
local repo_branch="test-branch"
# Given I prepare the link dotfiles repo outputs
local prev_dotfile_removal="rm -rf ${DOTFILES_REPO_LOCAL_PATH}"
local git_clone_command_custom_branch="git -C ${HOME}/.config clone --branch ${repo_branch} --single-branch ${repo_url} --quiet"
# And I run a link dotfiles repository command
./dotfiles.sh link "${repo_url}" "${repo_branch}" --dry-run -y -v >&"${TEST_log}" ||
echo "Failed to run dotfiles command"
# Then I expect the repo change dir output to exist
assert_expect_log "${prev_dotfile_removal}"
assert_expect_log "${git_clone_command_custom_branch}"
after_test
}
main() {
test_env_setup
test_dotfiles_version
test_dotfiles_sync_all
test_dotfiles_sync_home
test_dotfiles_sync_shell
test_dotfiles_unsync_all
test_dotfiles_unsync_home
test_dotfiles_unsync_shell
test_brew_prerequisites
test_brew_pacakges
test_brew_casks
test_brew_drivers
test_brew_services
test_brew_all
test_os_mac
test_os_linux
test_plugins_zsh
test_plugins_bash
test_reload_shell_session
test_change_dir_to_dotfiles_repo
test_link_dotfiles_repository_default_branch
test_link_dotfiles_repository_custom_branch
}
main "$@"