parent
23e4b38ef2
commit
c3a9b62189
@ -1,11 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
|
||||
@test "Syntax check" { |
||||
echo " |
||||
$T_YADM must parse correctly |
||||
" |
||||
|
||||
#; check the syntax of yadm |
||||
bash -n "$T_YADM" |
||||
} |
@ -1,209 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
|
||||
function configuration_test() { |
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
status=0 |
||||
output=$( process_global_args "$@" ) || { |
||||
status=$? |
||||
true |
||||
} |
||||
if [ "$status" == 0 ]; then |
||||
process_global_args "$@" |
||||
configure_paths |
||||
fi |
||||
|
||||
echo -e "STATUS:$status\nOUTPUT:$output" |
||||
echo "CONFIGURED PATHS:" |
||||
echo " YADM_DIR:$YADM_DIR" |
||||
echo " YADM_REPO:$YADM_REPO" |
||||
echo " YADM_CONFIG:$YADM_CONFIG" |
||||
echo " YADM_ENCRYPT:$YADM_ENCRYPT" |
||||
echo " YADM_ARCHIVE:$YADM_ARCHIVE" |
||||
echo "YADM_BOOTSTRAP:$YADM_BOOTSTRAP" |
||||
echo " GIT_DIR:$GIT_DIR" |
||||
} |
||||
|
||||
@test "Default paths" { |
||||
echo " |
||||
Default paths should be defined |
||||
YADM_DIR=$DEFAULT_YADM_DIR |
||||
YADM_REPO=$DEFAULT_YADM_DIR/$DEFAULT_REPO |
||||
YADM_CONFIG=$DEFAULT_YADM_DIR/$DEFAULT_CONFIG |
||||
YADM_ENCRYPT=$DEFAULT_YADM_DIR/$DEFAULT_ENCRYPT |
||||
YADM_ARCHIVE=$DEFAULT_YADM_DIR/$DEFAULT_ARCHIVE |
||||
YADM_BOOTSTRAP=$DEFAULT_YADM_DIR/$DEFAULT_BOOTSTRAP |
||||
GIT_DIR=$DEFAULT_YADM_DIR/$DEFAULT_REPO |
||||
" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$YADM_DIR" = "$HOME/.yadm" ] |
||||
[ "$YADM_REPO" = "$DEFAULT_YADM_DIR/$DEFAULT_REPO" ] |
||||
[ "$YADM_CONFIG" = "$DEFAULT_YADM_DIR/$DEFAULT_CONFIG" ] |
||||
[ "$YADM_ENCRYPT" = "$DEFAULT_YADM_DIR/$DEFAULT_ENCRYPT" ] |
||||
[ "$YADM_ARCHIVE" = "$DEFAULT_YADM_DIR/$DEFAULT_ARCHIVE" ] |
||||
[ "$YADM_BOOTSTRAP" = "$DEFAULT_YADM_DIR/$DEFAULT_BOOTSTRAP" ] |
||||
[ "$GIT_DIR" = "$DEFAULT_YADM_DIR/$DEFAULT_REPO" ] |
||||
} |
||||
|
||||
@test "Override YADM_DIR" { |
||||
echo " |
||||
Override YADM_DIR using -Y $T_DIR_YADM |
||||
YADM_DIR should become $T_DIR_YADM |
||||
" |
||||
|
||||
TEST_ARGS=(-Y $T_DIR_YADM) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$YADM_DIR" = "$T_DIR_YADM" ] |
||||
[ "$YADM_REPO" = "$T_DIR_YADM/$DEFAULT_REPO" ] |
||||
[ "$YADM_CONFIG" = "$T_DIR_YADM/$DEFAULT_CONFIG" ] |
||||
[ "$YADM_ENCRYPT" = "$T_DIR_YADM/$DEFAULT_ENCRYPT" ] |
||||
[ "$YADM_ARCHIVE" = "$T_DIR_YADM/$DEFAULT_ARCHIVE" ] |
||||
[ "$YADM_BOOTSTRAP" = "$T_DIR_YADM/$DEFAULT_BOOTSTRAP" ] |
||||
[ "$GIT_DIR" = "$T_DIR_YADM/$DEFAULT_REPO" ] |
||||
} |
||||
|
||||
@test "Override YADM_DIR (not fully-qualified)" { |
||||
echo " |
||||
Override YADM_DIR using -Y 'relative/path' |
||||
yadm should fail, and report the error |
||||
" |
||||
|
||||
TEST_ARGS=(-Y relative/path) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ must\ specify\ a\ fully\ qualified ]] |
||||
} |
||||
|
||||
@test "Override YADM_REPO" { |
||||
echo " |
||||
Override YADM_REPO using --yadm-repo /custom/repo |
||||
YADM_REPO should become /custom/repo |
||||
GIT_DIR should become /custom/repo |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-repo /custom/repo) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$YADM_REPO" = "/custom/repo" ] |
||||
[ "$GIT_DIR" = "/custom/repo" ] |
||||
} |
||||
|
||||
@test "Override YADM_REPO (not fully qualified)" { |
||||
echo " |
||||
Override YADM_REPO using --yadm-repo relative/repo |
||||
yadm should fail, and report the error |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-repo relative/repo) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ must\ specify\ a\ fully\ qualified ]] |
||||
} |
||||
|
||||
@test "Override YADM_CONFIG" { |
||||
echo " |
||||
Override YADM_CONFIG using --yadm-config /custom/config |
||||
YADM_CONFIG should become /custom/config |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-config /custom/config) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$YADM_CONFIG" = "/custom/config" ] |
||||
} |
||||
|
||||
@test "Override YADM_CONFIG (not fully qualified)" { |
||||
echo " |
||||
Override YADM_CONFIG using --yadm-config relative/config |
||||
yadm should fail, and report the error |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-config relative/config) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ must\ specify\ a\ fully\ qualified ]] |
||||
} |
||||
|
||||
@test "Override YADM_ENCRYPT" { |
||||
echo " |
||||
Override YADM_ENCRYPT using --yadm-encrypt /custom/encrypt |
||||
YADM_ENCRYPT should become /custom/encrypt |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-encrypt /custom/encrypt) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$YADM_ENCRYPT" = "/custom/encrypt" ] |
||||
} |
||||
|
||||
@test "Override YADM_ENCRYPT (not fully qualified)" { |
||||
echo " |
||||
Override YADM_ENCRYPT using --yadm-encrypt relative/encrypt |
||||
yadm should fail, and report the error |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-encrypt relative/encrypt) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ must\ specify\ a\ fully\ qualified ]] |
||||
} |
||||
|
||||
@test "Override YADM_ARCHIVE" { |
||||
echo " |
||||
Override YADM_ARCHIVE using --yadm-archive /custom/archive |
||||
YADM_ARCHIVE should become /custom/archive |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-archive /custom/archive) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$YADM_ARCHIVE" = "/custom/archive" ] |
||||
} |
||||
|
||||
@test "Override YADM_ARCHIVE (not fully qualified)" { |
||||
echo " |
||||
Override YADM_ARCHIVE using --yadm-archive relative/archive |
||||
yadm should fail, and report the error |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-archive relative/archive) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ must\ specify\ a\ fully\ qualified ]] |
||||
} |
||||
|
||||
@test "Override YADM_BOOTSTRAP" { |
||||
echo " |
||||
Override YADM_BOOTSTRAP using --yadm-bootstrap /custom/bootstrap |
||||
YADM_BOOTSTRAP should become /custom/bootstrap |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-bootstrap /custom/bootstrap) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$YADM_BOOTSTRAP" = "/custom/bootstrap" ] |
||||
} |
||||
|
||||
@test "Override YADM_BOOTSTRAP (not fully qualified)" { |
||||
echo " |
||||
Override YADM_BOOTSTRAP using --yadm-bootstrap relative/bootstrap |
||||
yadm should fail, and report the error |
||||
" |
||||
|
||||
TEST_ARGS=(--yadm-bootstrap relative/bootstrap) |
||||
configuration_test "${TEST_ARGS[@]}" |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ must\ specify\ a\ fully\ qualified ]] |
||||
} |
@ -1,67 +0,0 @@ |
||||
load common |
||||
T_YADM_CONFIG=; # populated by load_fixtures |
||||
load_fixtures |
||||
status=;output=; # populated by bats run() |
||||
|
||||
setup() { |
||||
destroy_tmp |
||||
make_parents "$T_YADM_CONFIG" |
||||
} |
||||
|
||||
teardown() { |
||||
destroy_tmp |
||||
} |
||||
|
||||
function configuration_test() { |
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
# shellcheck disable=SC2034 |
||||
YADM_CONFIG="$T_YADM_CONFIG" |
||||
status=0 |
||||
{ output=$( require_gpg ) && require_gpg; } || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
echo -e "STATUS:$status\nGPG_PROGRAM:$GPG_PROGRAM\nOUTPUT:$output" |
||||
|
||||
} |
||||
|
||||
@test "Default gpg program" { |
||||
echo " |
||||
Default gpg program should be 'gpg' |
||||
" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$GPG_PROGRAM" = "gpg" ] |
||||
} |
||||
|
||||
@test "Override gpg program (valid program)" { |
||||
echo " |
||||
Override gpg using yadm.gpg-program |
||||
Program should be 'cat' |
||||
" |
||||
|
||||
git config --file="$T_YADM_CONFIG" "yadm.gpg-program" "cat" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$GPG_PROGRAM" = "cat" ] |
||||
} |
||||
|
||||
@test "Override gpg program (invalid program)" { |
||||
echo " |
||||
Override gpg using yadm.gpg-program |
||||
Program should be 'badprogram' |
||||
" |
||||
|
||||
git config --file="$T_YADM_CONFIG" "yadm.gpg-program" "badprogram" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ badprogram ]] |
||||
} |
@ -1,67 +0,0 @@ |
||||
load common |
||||
T_YADM_CONFIG=; # populated by load_fixtures |
||||
load_fixtures |
||||
status=;output=; # populated by bats run() |
||||
|
||||
setup() { |
||||
destroy_tmp |
||||
make_parents "$T_YADM_CONFIG" |
||||
} |
||||
|
||||
teardown() { |
||||
destroy_tmp |
||||
} |
||||
|
||||
function configuration_test() { |
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
# shellcheck disable=SC2034 |
||||
YADM_CONFIG="$T_YADM_CONFIG" |
||||
status=0 |
||||
{ output=$( require_git ) && require_git; } || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
echo -e "STATUS:$status\nGIT_PROGRAM:$GIT_PROGRAM\nOUTPUT:$output" |
||||
|
||||
} |
||||
|
||||
@test "Default git program" { |
||||
echo " |
||||
Default git program should be 'git' |
||||
" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$GIT_PROGRAM" = "git" ] |
||||
} |
||||
|
||||
@test "Override git program (valid program)" { |
||||
echo " |
||||
Override git using yadm.git-program |
||||
Program should be 'cat' |
||||
" |
||||
|
||||
git config --file="$T_YADM_CONFIG" "yadm.git-program" "cat" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$GIT_PROGRAM" = "cat" ] |
||||
} |
||||
|
||||
@test "Override git program (invalid program)" { |
||||
echo " |
||||
Override git using yadm.git-program |
||||
Program should be 'badprogram' |
||||
" |
||||
|
||||
git config --file="$T_YADM_CONFIG" "yadm.git-program" "badprogram" |
||||
|
||||
configuration_test |
||||
|
||||
[ "$status" == 1 ] |
||||
[[ "$output" =~ badprogram ]] |
||||
} |
@ -1,66 +0,0 @@ |
||||
load common |
||||
T_YADM_BOOTSTRAP=; # populated by load_fixtures |
||||
load_fixtures |
||||
status=; # populated by bats run() |
||||
|
||||
setup() { |
||||
destroy_tmp |
||||
make_parents "$T_YADM_BOOTSTRAP" |
||||
} |
||||
|
||||
teardown() { |
||||
destroy_tmp |
||||
} |
||||
|
||||
function available_test() { |
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
# shellcheck disable=SC2034 |
||||
YADM_BOOTSTRAP="$T_YADM_BOOTSTRAP" |
||||
status=0 |
||||
{ bootstrap_available; } || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
echo -e "STATUS:$status" |
||||
|
||||
} |
||||
|
||||
@test "Bootstrap missing" { |
||||
echo " |
||||
When bootstrap command is missing |
||||
return 1 |
||||
" |
||||
|
||||
available_test |
||||
[ "$status" == 1 ] |
||||
|
||||
} |
||||
|
||||
@test "Bootstrap not executable" { |
||||
echo " |
||||
When bootstrap command is not executable |
||||
return 1 |
||||
" |
||||
|
||||
touch "$T_YADM_BOOTSTRAP" |
||||
|
||||
available_test |
||||
[ "$status" == 1 ] |
||||
|
||||
} |
||||
|
||||
@test "Bootstrap executable" { |
||||
echo " |
||||
When bootstrap command is not executable |
||||
return 0 |
||||
" |
||||
|
||||
touch "$T_YADM_BOOTSTRAP" |
||||
chmod a+x "$T_YADM_BOOTSTRAP" |
||||
|
||||
available_test |
||||
[ "$status" == 0 ] |
||||
|
||||
} |
@ -1,76 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
|
||||
@test "Default OS" { |
||||
echo " |
||||
By default, the value of OPERATING_SYSTEM should be reported by uname -s |
||||
" |
||||
|
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
status=0 |
||||
output=$( set_operating_system; echo "$OPERATING_SYSTEM" ) || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
expected=$(uname -s 2>/dev/null) |
||||
|
||||
echo "output=$output" |
||||
echo "expect=$expected" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" = "$expected" ] |
||||
} |
||||
|
||||
@test "Detect no WSL" { |
||||
echo " |
||||
When /proc/version does not contain Microsoft, report uname -s |
||||
" |
||||
|
||||
echo "proc version exists" > "$BATS_TMPDIR/proc_version" |
||||
|
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
# shellcheck disable=SC2034 |
||||
PROC_VERSION="$BATS_TMPDIR/proc_version" |
||||
status=0 |
||||
output=$( set_operating_system; echo "$OPERATING_SYSTEM" ) || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
expected=$(uname -s 2>/dev/null) |
||||
|
||||
echo "output=$output" |
||||
echo "expect=$expected" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" = "$expected" ] |
||||
} |
||||
|
||||
@test "Detect WSL" { |
||||
echo " |
||||
When /proc/version contains Microsoft, report WSL |
||||
" |
||||
|
||||
echo "proc version contains Microsoft in it" > "$BATS_TMPDIR/proc_version" |
||||
|
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
# shellcheck disable=SC2034 |
||||
PROC_VERSION="$BATS_TMPDIR/proc_version" |
||||
status=0 |
||||
output=$( set_operating_system; echo "$OPERATING_SYSTEM" ) || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
expected="WSL" |
||||
|
||||
echo "output=$output" |
||||
echo "expect=$expected" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" = "$expected" ] |
||||
} |
@ -1,49 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
|
||||
@test "Query distro (lsb_release present)" { |
||||
echo " |
||||
Use value of lsb_release -si |
||||
" |
||||
|
||||
#shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
status=0 |
||||
{ output=$( query_distro ); } || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
expected="${T_DISTRO}" |
||||
|
||||
echo "output=$output" |
||||
echo "expect=$expected" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" = "$expected" ] |
||||
} |
||||
|
||||
@test "Query distro (lsb_release missing)" { |
||||
echo " |
||||
Empty value if lsb_release is missing |
||||
" |
||||
|
||||
#shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
LSB_RELEASE_PROGRAM="missing_lsb_release" |
||||
echo "Using $LSB_RELEASE_PROGRAM as lsb_release" |
||||
|
||||
status=0 |
||||
{ output=$( query_distro ); } || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
expected="" |
||||
|
||||
echo "output=$output" |
||||
echo "expect=$expected" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" = "$expected" ] |
||||
} |
@ -1,318 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
|
||||
setup() { |
||||
# SC2153 is intentional |
||||
# shellcheck disable=SC2153 |
||||
make_parents "$T_YADM_ENCRYPT" |
||||
make_parents "$T_DIR_WORK" |
||||
make_parents "$T_DIR_REPO" |
||||
mkdir "$T_DIR_WORK" |
||||
git init --shared=0600 --bare "$T_DIR_REPO" >/dev/null 2>&1 |
||||
GIT_DIR="$T_DIR_REPO" git config core.bare 'false' |
||||
GIT_DIR="$T_DIR_REPO" git config core.worktree "$T_DIR_WORK" |
||||
GIT_DIR="$T_DIR_REPO" git config yadm.managed 'true' |
||||
} |
||||
|
||||
teardown() { |
||||
destroy_tmp |
||||
} |
||||
|
||||
function run_parse() { |
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
YADM_ENCRYPT="$T_YADM_ENCRYPT" |
||||
export YADM_ENCRYPT |
||||
GIT_DIR="$T_DIR_REPO" |
||||
export GIT_DIR |
||||
|
||||
# shellcheck disable=SC2034 |
||||
|
||||
status=0 |
||||
{ output=$( parse_encrypt) && parse_encrypt; } || { |
||||
status=$? |
||||
true |
||||
} |
||||
|
||||
if [ "$1" == "twice" ]; then |
||||
GIT_DIR="$T_DIR_REPO" parse_encrypt |
||||
fi |
||||
|
||||
echo -e "OUTPUT:$output\n" |
||||
echo "ENCRYPT_INCLUDE_FILES:" |
||||
echo " Size: ${#ENCRYPT_INCLUDE_FILES[@]}" |
||||
echo " Items: ${ENCRYPT_INCLUDE_FILES[*]}" |
||||
echo "EXPECT_INCLUDE:" |
||||
echo " Size: ${#EXPECT_INCLUDE[@]}" |
||||
echo " Items: ${EXPECT_INCLUDE[*]}" |
||||
} |
||||
|
||||
@test "parse_encrypt (not called)" { |
||||
echo " |
||||
parse_encrypt() is not called |
||||
Array should be 'unparsed' |
||||
" |
||||
|
||||
# shellcheck source=/dev/null |
||||
YADM_TEST=1 source "$T_YADM" |
||||
|
||||
echo "ENCRYPT_INCLUDE_FILES=$ENCRYPT_INCLUDE_FILES" |
||||
|
||||
[ "$ENCRYPT_INCLUDE_FILES" == "unparsed" ] |
||||
|
||||
} |
||||
|
||||
@test "parse_encrypt (short-circuit)" { |
||||
echo " |
||||
Parsing should not happen more than once |
||||
" |
||||
|
||||
run_parse "twice" |
||||
echo "PARSE_ENCRYPT_SHORT: $PARSE_ENCRYPT_SHORT" |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[[ "$PARSE_ENCRYPT_SHORT" =~ not\ reprocessed ]] |
||||
} |
||||
|
||||
@test "parse_encrypt (file missing)" { |
||||
echo " |
||||
.yadm/encrypt is empty |
||||
Array should be empty |
||||
" |
||||
|
||||
EXPECT_INCLUDE=() |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (empty file)" { |
||||
echo " |
||||
.yadm/encrypt is empty |
||||
Array should be empty |
||||
" |
||||
|
||||
touch "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=() |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (files)" { |
||||
echo " |
||||
.yadm/encrypt is references present and missing files |
||||
Array should be as expected |
||||
" |
||||
|
||||
echo "file1" > "$T_DIR_WORK/file1" |
||||
echo "file3" > "$T_DIR_WORK/file3" |
||||
echo "file5" > "$T_DIR_WORK/file5" |
||||
|
||||
{ echo "file1" |
||||
echo "file2" |
||||
echo "file3" |
||||
echo "file4" |
||||
echo "file5" |
||||
} > "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=("file1" "file3" "file5") |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (files and dirs)" { |
||||
echo " |
||||
.yadm/encrypt is references present and missing files |
||||
.yadm/encrypt is references present and missing dirs |
||||
Array should be as expected |
||||
" |
||||
|
||||
mkdir -p "$T_DIR_WORK/dir1" |
||||
mkdir -p "$T_DIR_WORK/dir2" |
||||
echo "file1" > "$T_DIR_WORK/file1" |
||||
echo "file2" > "$T_DIR_WORK/file2" |
||||
echo "a" > "$T_DIR_WORK/dir1/a" |
||||
echo "b" > "$T_DIR_WORK/dir1/b" |
||||
|
||||
{ echo "file1" |
||||
echo "file2" |
||||
echo "file3" |
||||
echo "dir1" |
||||
echo "dir2" |
||||
echo "dir3" |
||||
} > "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=("file1" "file2" "dir1" "dir2") |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (comments/empty lines)" { |
||||
echo " |
||||
.yadm/encrypt is references present and missing files |
||||
.yadm/encrypt is references present and missing dirs |
||||
.yadm/encrypt contains comments / blank lines |
||||
Array should be as expected |
||||
" |
||||
|
||||
mkdir -p "$T_DIR_WORK/dir1" |
||||
mkdir -p "$T_DIR_WORK/dir2" |
||||
echo "file1" > "$T_DIR_WORK/file1" |
||||
echo "file2" > "$T_DIR_WORK/file2" |
||||
echo "file3" > "$T_DIR_WORK/file3" |
||||
echo "a" > "$T_DIR_WORK/dir1/a" |
||||
echo "b" > "$T_DIR_WORK/dir1/b" |
||||
|
||||
{ echo "file1" |
||||
echo "file2" |
||||
echo "#file3" |
||||
echo " #file3" |
||||
echo "" |
||||
echo "dir1" |
||||
echo "dir2" |
||||
echo "dir3" |
||||
} > "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=("file1" "file2" "dir1" "dir2") |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (w/spaces)" { |
||||
echo " |
||||
.yadm/encrypt is references present and missing files |
||||
.yadm/encrypt is references present and missing dirs |
||||
.yadm/encrypt references contain spaces |
||||
Array should be as expected |
||||
" |
||||
|
||||
mkdir -p "$T_DIR_WORK/di r1" |
||||
mkdir -p "$T_DIR_WORK/dir2" |
||||
echo "file1" > "$T_DIR_WORK/file1" |
||||
echo "fi le2" > "$T_DIR_WORK/fi le2" |
||||
echo "file3" > "$T_DIR_WORK/file3" |
||||
echo "a" > "$T_DIR_WORK/di r1/a" |
||||
echo "b" > "$T_DIR_WORK/di r1/b" |
||||
|
||||
{ echo "file1" |
||||
echo "fi le2" |
||||
echo "#file3" |
||||
echo " #file3" |
||||
echo "" |
||||
echo "di r1" |
||||
echo "dir2" |
||||
echo "dir3" |
||||
} > "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=("file1" "fi le2" "di r1" "dir2") |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (wildcards)" { |
||||
echo " |
||||
.yadm/encrypt contains wildcards |
||||
Array should be as expected |
||||
" |
||||
|
||||
mkdir -p "$T_DIR_WORK/di r1" |
||||
mkdir -p "$T_DIR_WORK/dir2" |
||||
echo "file1" > "$T_DIR_WORK/file1" |
||||
echo "fi le2" > "$T_DIR_WORK/fi le2" |
||||
echo "file2" > "$T_DIR_WORK/file2" |
||||
echo "file3" > "$T_DIR_WORK/file3" |
||||
echo "a" > "$T_DIR_WORK/di r1/a" |
||||
echo "b" > "$T_DIR_WORK/di r1/b" |
||||
|
||||
{ echo "fi*" |
||||
echo "#file3" |
||||
echo " #file3" |
||||
echo "" |
||||
echo "#dir2" |
||||
echo "di r1" |
||||
echo "dir2" |
||||
echo "dir3" |
||||
} > "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=("fi le2" "file1" "file2" "file3" "di r1" "dir2") |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
||||
|
||||
@test "parse_encrypt (excludes)" { |
||||
echo " |
||||
.yadm/encrypt contains exclusions |
||||
Array should be as expected |
||||
" |
||||
|
||||
mkdir -p "$T_DIR_WORK/di r1" |
||||
mkdir -p "$T_DIR_WORK/dir2" |
||||
mkdir -p "$T_DIR_WORK/dir3" |
||||
echo "file1" > "$T_DIR_WORK/file1" |
||||
echo "file1.ex" > "$T_DIR_WORK/file1.ex" |
||||
echo "fi le2" > "$T_DIR_WORK/fi le2" |
||||
echo "file3" > "$T_DIR_WORK/file3" |
||||
echo "test" > "$T_DIR_WORK/test" |
||||
echo "a.txt" > "$T_DIR_WORK/di r1/a.txt" |
||||
echo "b.txt" > "$T_DIR_WORK/di r1/b.txt" |
||||
echo "c.inc" > "$T_DIR_WORK/di r1/c.inc" |
||||
|
||||
{ echo "fi*" |
||||
echo "#file3" |
||||
echo " #file3" |
||||
echo "" |
||||
echo " #test" |
||||
echo "#dir2" |
||||
echo "di r1/*" |
||||
echo "dir2" |
||||
echo "dir3" |
||||
echo "dir4" |
||||
echo "!*.ex" |
||||
echo "!di r1/*.txt" |
||||
} > "$T_YADM_ENCRYPT" |
||||
|
||||
EXPECT_INCLUDE=("fi le2" "file1" "file3" "di r1/c.inc" "dir2" "dir3") |
||||
|
||||
run_parse |
||||
|
||||
[ "$status" == 0 ] |
||||
[ "$output" == "" ] |
||||
[ "${#ENCRYPT_INCLUDE_FILES[@]}" -eq "${#EXPECT_INCLUDE[@]}" ] |
||||
[ "${ENCRYPT_INCLUDE_FILES[*]}" == "${EXPECT_INCLUDE[*]}" ] |
||||
} |
@ -1,25 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
status=;output=; #; populated by bats run() |
||||
|
||||
@test "Command 'version'" { |
||||
echo " |
||||
When 'version' command is provided, |
||||
Print the current version with format 'yadm x.x.x' |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; run yadm with 'version' command |
||||
run "$T_YADM" version |
||||
|
||||
# shellcheck source=/dev/null |
||||
|
||||
#; load yadm variables (including VERSION) |
||||
YADM_TEST=1 source "$T_YADM" |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 0 ] |
||||
[ "$output" = "yadm $VERSION" ] |
||||
version_regex="^yadm [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$" |
||||
[[ "$output" =~ $version_regex ]] |
||||
} |
@ -1,33 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
status=;lines=; #; populated by bats run() |
||||
|
||||
@test "Missing command" { |
||||
echo " |
||||
When no command is provided, |
||||
Produce usage instructions |
||||
Exit with 1 |
||||
" |
||||
|
||||
#; run yadm with no command |
||||
run "$T_YADM" |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 1 ] |
||||
[[ "${lines[0]}" =~ ^Usage: ]] |
||||
} |
||||
|
||||
@test "Command 'help'" { |
||||
echo " |
||||
When 'help' command is provided, |
||||
Produce usage instructions |
||||
Exit with value 1 |
||||
" |
||||
|
||||
#; run yadm with 'help' command |
||||
run "$T_YADM" help |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 1 ] |
||||
[[ "${lines[0]}" =~ ^Usage: ]] |
||||
} |
@ -1,19 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
status=;lines=; #; populated by bats run() |
||||
|
||||
@test "Command 'clean'" { |
||||
echo " |
||||
When 'clean' command is provided, |
||||
Do nothing, this is a dangerous Git command when managing dot files |
||||
Report the command as disabled |
||||
Exit with 1 |
||||
" |
||||
|
||||
#; run yadm with 'clean' command |
||||
run "$T_YADM" clean |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 1 ] |
||||
[[ "${lines[0]}" =~ disabled ]] |
||||
} |
@ -1,117 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
status=;output=;lines=; #; populated by bats run() |
||||
|
||||
IN_REPO=(.bash_profile .vimrc) |
||||
|
||||
function setup_environment() { |
||||
destroy_tmp |
||||
build_repo "${IN_REPO[@]}" |
||||
} |
||||
|
||||
@test "Passthru unknown commands to Git" { |
||||
echo " |
||||
When the command 'bogus' is provided |
||||
Report bogus is not a command |
||||
Exit with 1 |
||||
" |
||||
|
||||
#; start fresh |
||||
setup_environment |
||||
|
||||
#; run bogus |
||||
run "${T_YADM_Y[@]}" bogus |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 1 ] |
||||
[[ "$output" =~ .bogus..is.not.a.git.command ]] |
||||
} |
||||
|
||||
@test "Git command 'add' - badfile" { |
||||
echo " |
||||
When the command 'add' is provided |
||||
And the file specified does not exist |
||||
Exit with 128 |
||||
" |
||||
|
||||
#; start fresh |
||||
setup_environment |
||||
|
||||
#; define a non existig testfile |
||||
local testfile="$T_DIR_WORK/does_not_exist" |
||||
|
||||
#; run add |
||||
run "${T_YADM_Y[@]}" add -v "$testfile" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 128 ] |
||||
[[ "$output" =~ pathspec.+did.not.match ]] |
||||
} |
||||
|
||||
@test "Git command 'add'" { |
||||
echo " |
||||
When the command 'add' is provided |
||||
Files are added to the index |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; start fresh |
||||
setup_environment |
||||
|
||||
#; create a testfile |
||||
local testfile="$T_DIR_WORK/testfile" |
||||
echo "$testfile" > "$testfile" |
||||
|
||||
#; run add |
||||
run "${T_YADM_Y[@]}" add -v "$testfile" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[ "$output" = "add 'testfile'" ] |
||||
} |
||||
|
||||
@test "Git command 'status'" { |
||||
echo " |
||||
When the command 'status' is provided |
||||
Added files are shown |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; run status |
||||
run "${T_YADM_Y[@]}" status |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "$output" =~ new\ file:[[:space:]]+testfile ]] |
||||
} |
||||
|
||||
@test "Git command 'commit'" { |
||||
echo " |
||||
When the command 'commit' is provided |
||||
Index is commited |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; run commit |
||||
run "${T_YADM_Y[@]}" commit -m 'Add testfile' |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "${lines[1]}" =~ 1\ file\ changed ]] |
||||
[[ "${lines[1]}" =~ 1\ insertion ]] |
||||
} |
||||
|
||||
@test "Git command 'log'" { |
||||
echo " |
||||
When the command 'log' is provided |
||||
Commits are shown |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; run log |
||||
run "${T_YADM_Y[@]}" log --oneline |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "${lines[0]}" =~ Add\ testfile ]] |
||||
} |
@ -1,178 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
status=;output=; #; populated by bats run() |
||||
|
||||
setup() { |
||||
destroy_tmp |
||||
create_worktree "$T_DIR_WORK" |
||||
} |
||||
|
||||
@test "Command 'init'" { |
||||
echo " |
||||
When 'init' command is provided, |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$HOME |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as initialized |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; run init |
||||
run "${T_YADM_Y[@]}" init |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$HOME" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
} |
||||
|
||||
@test "Command 'init' -w (alternate worktree)" { |
||||
echo " |
||||
When 'init' command is provided, |
||||
and '-w' is provided, |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as initialized |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; run init |
||||
run "${T_YADM_Y[@]}" init -w "$T_DIR_WORK" |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
} |
||||
|
||||
@test "Command 'init' (existing repo)" { |
||||
echo " |
||||
When 'init' command is provided, |
||||
and a repo already exists, |
||||
Refuse to create a new repo |
||||
Exit with 1 |
||||
" |
||||
|
||||
#; create existing repo content |
||||
mkdir -p "$T_DIR_REPO" |
||||
local testfile="$T_DIR_REPO/testfile" |
||||
touch "$testfile" |
||||
|
||||
#; run init |
||||
run "${T_YADM_Y[@]}" init |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 1 ] |
||||
[[ "$output" =~ already.exists ]] |
||||
|
||||
#; verify existing repo is intact |
||||
if [ ! -e "$testfile" ]; then |
||||
echo "ERROR: existing repo has been changed" |
||||
return 1 |
||||
fi |
||||
|
||||
} |
||||
|
||||
@test "Command 'init' -f (force overwrite repo)" { |
||||
echo " |
||||
When 'init' command is provided, |
||||
and '-f' is provided |
||||
and a repo already exists, |
||||
Remove existing repo |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$HOME |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as initialized |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; create existing repo content |
||||
mkdir -p "$T_DIR_REPO" |
||||
local testfile="$T_DIR_REPO/testfile" |
||||
touch "$testfile" |
||||
|
||||
#; run init |
||||
run "${T_YADM_Y[@]}" init -f |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; verify existing repo is gone |
||||
if [ -e "$testfile" ]; then |
||||
echo "ERROR: existing repo files remain" |
||||
return 1 |
||||
fi |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$HOME" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
} |
||||
|
||||
@test "Command 'init' -f -w (force overwrite repo with alternate worktree)" { |
||||
echo " |
||||
When 'init' command is provided, |
||||
and '-f' is provided |
||||
and '-w' is provided |
||||
and a repo already exists, |
||||
Remove existing repo |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as initialized |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; create existing repo content |
||||
mkdir -p "$T_DIR_REPO" |
||||
local testfile="$T_DIR_REPO/testfile" |
||||
touch "$testfile" |
||||
|
||||
#; run init |
||||
run "${T_YADM_Y[@]}" init -f -w "$T_DIR_WORK" |
||||
|
||||
#; validate status and output |
||||
[ $status -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; verify existing repo is gone |
||||
if [ -e "$testfile" ]; then |
||||
echo "ERROR: existing repo files remain" |
||||
return 1 |
||||
fi |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
} |
@ -1,579 +0,0 @@ |
||||
load common |
||||
load_fixtures |
||||
status=;output=; #; populated by bats run() |
||||
|
||||
IN_REPO=(.bash_profile .vimrc) |
||||
T_DIR_REMOTE="$T_TMP/remote" |
||||
REMOTE_URL="file:///$T_TMP/remote" |
||||
|
||||
setup() { |
||||
destroy_tmp |
||||
build_repo "${IN_REPO[@]}" |
||||
cp -rp "$T_DIR_REPO" "$T_DIR_REMOTE" |
||||
} |
||||
|
||||
create_bootstrap() { |
||||
make_parents "$T_YADM_BOOTSTRAP" |
||||
{ |
||||
echo "#!/bin/bash" |
||||
echo "echo Bootstrap successful" |
||||
echo "exit 123" |
||||
} > "$T_YADM_BOOTSTRAP" |
||||
chmod a+x "$T_YADM_BOOTSTRAP" |
||||
} |
||||
|
||||
@test "Command 'clone' (bad remote)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
and the remote is bad, |
||||
Report error |
||||
Remove the YADM_REPO |
||||
Exit with 1 |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone -w "$T_DIR_WORK" "file:///bogus-repo" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 1 ] |
||||
[[ "$output" =~ Unable\ to\ fetch\ origin ]] |
||||
|
||||
#; confirm repo directory is removed |
||||
[ ! -d "$T_DIR_REPO" ] |
||||
} |
||||
|
||||
@test "Command 'clone'" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone -w "$T_DIR_WORK" "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
} |
||||
|
||||
@test "Command 'clone' (existing repo)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
and a repo already exists, |
||||
Report error |
||||
Exit with 1 |
||||
" |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone -w "$T_DIR_WORK" "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 1 ] |
||||
[[ "$output" =~ Git\ repo\ already\ exists ]] |
||||
} |
||||
|
||||
@test "Command 'clone' -f (force overwrite)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
and '-f' is provided, |
||||
and a repo already exists, |
||||
Overwrite the repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; remove existing worktree |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone -w "$T_DIR_WORK" -f "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
} |
||||
|
||||
@test "Command 'clone' (existing conflicts)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
and '-f' is provided, |
||||
and a repo already exists, |
||||
Overwrite the repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; remove existing repo |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; cause a conflict |
||||
echo "conflict" >> "$T_DIR_WORK/.bash_profile" |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone -w "$T_DIR_WORK" "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; validate merging note |
||||
[[ "$output" =~ Merging\ origin/master\ failed ]] |
||||
[[ "$output" =~ NOTE ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
|
||||
#; confirm yadm repo is clean |
||||
cd "$T_DIR_WORK" ||: |
||||
clean_status=$("${T_YADM_Y[@]}" status -uno --porcelain) |
||||
echo "clean_status:'$clean_status'" |
||||
[ -z "$clean_status" ] |
||||
|
||||
#; confirm conflicts are stashed |
||||
existing_stash=$("${T_YADM_Y[@]}" stash list) |
||||
echo "existing_stash:'$existing_stash'" |
||||
[[ "$existing_stash" =~ Conflicts\ preserved ]] |
||||
|
||||
stashed_conflicts=$("${T_YADM_Y[@]}" stash show -p) |
||||
echo "stashed_conflicts:'$stashed_conflicts'" |
||||
[[ "$stashed_conflicts" =~ \+conflict ]] |
||||
|
||||
} |
||||
|
||||
@test "Command 'clone' (force bootstrap, missing)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
with the --bootstrap parameter |
||||
and bootstrap does not exists |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone --bootstrap -w "$T_DIR_WORK" "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
} |
||||
|
||||
@test "Command 'clone' (force bootstrap, existing)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
with the --bootstrap parameter |
||||
and bootstrap exists |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Run the bootstrap |
||||
Exit with bootstrap's exit code |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; create the bootstrap |
||||
create_bootstrap |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone --bootstrap -w "$T_DIR_WORK" "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 123 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
[[ "$output" =~ Bootstrap\ successful ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
} |
||||
|
||||
@test "Command 'clone' (prevent bootstrap)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
with the --no-bootstrap parameter |
||||
and bootstrap exists |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Do NOT run bootstrap |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; create the bootstrap |
||||
create_bootstrap |
||||
|
||||
#; run clone |
||||
run "${T_YADM_Y[@]}" clone --no-bootstrap -w "$T_DIR_WORK" "$REMOTE_URL" |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ $output =~ Initialized ]] |
||||
[[ ! $output =~ Bootstrap\ successful ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
} |
||||
|
||||
@test "Command 'clone' (existing bootstrap, answer n)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
and bootstrap exists |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Do NOT run bootstrap |
||||
Exit with 0 |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||
rm -rf "$T_DIR_WORK" |
||||
mkdir -p "$T_DIR_WORK" |
||||
rm -rf "$T_DIR_REPO" |
||||
|
||||
#; create the bootstrap |
||||
create_bootstrap |
||||
|
||||
#; run clone |
||||
run expect <<EOF |
||||
set timeout 2; |
||||
spawn ${T_YADM_Y[*]} clone -w "$T_DIR_WORK" "$REMOTE_URL"; |
||||
expect "Would you like to execute it now" {send "n\n"} |
||||
expect "$" |
||||
foreach {pid spawnid os_error_flag value} [wait] break |
||||
exit \$value |
||||
EOF |
||||
|
||||
#; validate status and output |
||||
[ "$status" -eq 0 ] |
||||
[[ "$output" =~ Initialized ]] |
||||
[[ ! "$output" =~ Bootstrap\ successful ]] |
||||
|
||||
#; validate repo attributes |
||||
test_perms "$T_DIR_REPO" "drw.--.--." |
||||
test_repo_attribute "$T_DIR_REPO" core.bare false |
||||
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK" |
||||
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no |
||||
test_repo_attribute "$T_DIR_REPO" yadm.managed true |
||||
|
||||
#; test the remote |
||||
local remote_output |
||||
remote_output=$(GIT_DIR="$T_DIR_REPO" git remote show) |
||||
[ "$remote_output" = "origin" ] |
||||
} |
||||
|
||||
@test "Command 'clone' (existing bootstrap, answer y)" { |
||||
echo " |
||||
When 'clone' command is provided, |
||||
and bootstrap exists |
||||
Create new repo with attributes: |
||||
- 0600 permissions |
||||
- not bare |
||||
- worktree = \$YADM_WORK |
||||
- showUntrackedFiles = no |
||||
- yadm.managed = true |
||||
Report the repo as cloned |
||||
A remote named origin exists |
||||
Run the bootstrap |
||||
Exit with bootstrap's exit code |
||||
" |
||||
|
||||
#; remove existing worktree and repo |
||||