2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-17 21:25:32 +00:00

finit test

This commit is contained in:
kevin zhuang 2020-05-13 12:02:58 +10:00
parent bdd77bcd17
commit 32e6d0099f
2 changed files with 45 additions and 2 deletions

View File

@ -18,7 +18,7 @@ source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/get_confirmation.sh
function usage() {
echo -e "Usage: dotbare finit [-h] ...\n"
echo -e "Usage: dotbare finit [-h] [-u] ...\n"
echo -e "Init the git bare repository if doesn't exist"
# shellcheck disable=SC2016
echo -e 'The bare repository will be initialised under ${DOTBARE_DIR}, default to $HOME/.cfg if not set'
@ -52,11 +52,12 @@ if [[ -z "${remote_url}" ]]; then
echo "modify DOTBARE_DIR and DOTBARE_TREE to customize location, more information run dotbare finit -h"
echo "git bare repository will be initialised at ${DOTBARE_DIR}"
echo "git bare repository will be tracking ${DOTBARE_TREE}"
confirm=$(get_confirmation)
[[ -z "${confirm}" ]] && confirm=$(get_confirmation)
[[ "${confirm}" != 'y' ]] && exit 1
if [[ -d "${DOTBARE_DIR}" ]]; then
echo "${DOTBARE_DIR} already exist"
exit 1
else
git init --bare "${DOTBARE_DIR}"
/usr/bin/git --git-dir "${DOTBARE_DIR}" --work-tree "${DOTBARE_TREE}" \

42
tests/finit.bats Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bats
setup() {
export confirm='y'
export DOTBARE_DIR="$HOME/.local/share/dotbare_test/.cfg"
export DOTBARE_TREE="$HOME/.local/share/dotbare_test"
}
teardown() {
unset confirm
}
help() {
bash "${BATS_TEST_DIRNAME}"/../dotbare finit -h
}
init() {
bash "${BATS_TEST_DIRNAME}"/../dotbare finit
}
migration() {
bash "${BATS_TEST_DIRNAME}"/../dotbare finit -u https://github.com/kazhala/dotfiles.git
}
@test "finit help" {
run help
[ "${status}" -eq 0 ]
[ "${lines[0]}" = "Usage: dotbare finit [-h] [-u] ..." ]
}
@test "init dotbare" {
run init
[ "${status}" -eq 0 ]
run init
[ "${status}" -eq 1 ]
[ "${lines[3]}" = "${DOTBARE_DIR} already exist" ]
}
@test "migration" {
run migration
[ "${status}" -eq 0 ]
}