2020-05-13 01:26:37 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
export DOTBARE_BACKUP="$HOME/.local/share/dotbare_test"
|
2020-05-13 11:04:02 +00:00
|
|
|
export DOTBARE_DIR="${HOME}/.cfg/"
|
2020-05-13 01:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2020-06-25 01:07:13 +00:00
|
|
|
[ -d "${DOTBARE_BACKUP}" ] && rm -r "${DOTBARE_BACKUP}"
|
2020-05-13 01:26:37 +00:00
|
|
|
unset DOTBARE_BACKUP
|
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
|
|
|
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -h
|
|
|
|
}
|
|
|
|
|
|
|
|
invalid_option() {
|
|
|
|
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -f
|
|
|
|
}
|
|
|
|
|
|
|
|
backup() {
|
|
|
|
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup
|
|
|
|
}
|
|
|
|
|
|
|
|
individual_backup() {
|
|
|
|
cd "${BATS_TEST_DIRNAME}"
|
|
|
|
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -p fadd.bats
|
|
|
|
}
|
|
|
|
|
2020-06-25 01:07:13 +00:00
|
|
|
move_file() {
|
|
|
|
touch bats_test.txt
|
|
|
|
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup --path bats_test.txt -m
|
|
|
|
}
|
|
|
|
|
|
|
|
select_file() {
|
|
|
|
export PATH="${BATS_TEST_DIRNAME}:$PATH"
|
|
|
|
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup --select
|
2020-05-15 07:36:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 01:26:37 +00:00
|
|
|
@test "fbackup help" {
|
|
|
|
run help
|
|
|
|
[ "${status}" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "fbackup invalid option" {
|
|
|
|
run invalid_option
|
|
|
|
[ "${status}" -eq 1 ]
|
2020-06-25 01:07:13 +00:00
|
|
|
[ "${lines[0]}" = 'Invalid option: -f' ]
|
2020-05-13 01:26:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 03:41:58 +00:00
|
|
|
@test "fbackup backup all files" {
|
2020-06-25 01:07:13 +00:00
|
|
|
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
|
2020-05-13 11:04:02 +00:00
|
|
|
run backup
|
2020-06-25 01:07:13 +00:00
|
|
|
[ "${status}" -eq 1 ]
|
2020-05-15 07:36:18 +00:00
|
|
|
else
|
2020-05-15 08:04:43 +00:00
|
|
|
run backup
|
2020-06-25 01:07:13 +00:00
|
|
|
[ "${status}" -eq 0 ]
|
|
|
|
[ -f "${DOTBARE_BACKUP}"/.bashrc ]
|
2020-05-13 11:04:02 +00:00
|
|
|
fi
|
2020-05-13 01:26:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 03:41:58 +00:00
|
|
|
@test "fbackup backup individual file" {
|
2020-05-13 01:26:37 +00:00
|
|
|
run individual_backup
|
|
|
|
[ "${status}" -eq 0 ]
|
2020-05-15 07:36:18 +00:00
|
|
|
[ -f "${DOTBARE_BACKUP}"/fadd.bats ]
|
2020-05-13 01:26:37 +00:00
|
|
|
}
|
2020-06-25 01:07:13 +00:00
|
|
|
|
|
|
|
@test "fbackup move file" {
|
|
|
|
run move_file
|
|
|
|
[ "${status}" -eq 0 ]
|
|
|
|
[ -f "${DOTBARE_BACKUP}"/bats_test.txt ]
|
|
|
|
[ ! -f "${BATS_TEST_DIRNAME}"/bats_test.txt ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "fbackup select file" {
|
|
|
|
run select_file
|
|
|
|
[ "${status}" -eq 1 ]
|
|
|
|
[[ "${output}" =~ 'cp: selectgitfile: No such file or directory' ]]
|
|
|
|
}
|