Remove BATS-based tests
This commit is contained in:
parent
23e4b38ef2
commit
c3a9b62189
28 changed files with 0 additions and 5064 deletions
|
@ -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
|
|
||||||
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 "y\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; 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' (local insecure .ssh and .gnupg data, no related data in repo)" {
|
|
||||||
echo "
|
|
||||||
Local .ssh/.gnupg data exists and is insecure
|
|
||||||
but yadm repo contains no .ssh/.gnupg data
|
|
||||||
local insecure data should remain accessible
|
|
||||||
(yadm is hands-off)
|
|
||||||
"
|
|
||||||
#; setup scenario
|
|
||||||
rm -rf "$T_DIR_WORK" "$T_DIR_REPO"
|
|
||||||
mkdir -p "$T_DIR_WORK/.ssh"
|
|
||||||
mkdir -p "$T_DIR_WORK/.gnupg"
|
|
||||||
touch "$T_DIR_WORK/.ssh/testfile"
|
|
||||||
touch "$T_DIR_WORK/.gnupg/testfile"
|
|
||||||
find "$T_DIR_WORK" -exec chmod a+rw '{}' ';'
|
|
||||||
|
|
||||||
#; run clone (with debug on)
|
|
||||||
run "${T_YADM_Y[@]}" clone -d -w "$T_DIR_WORK" "$REMOTE_URL"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Initialized ]]
|
|
||||||
[[ "$output" =~ initial\ private\ dir\ perms\ drwxrwxrwx.+\.ssh ]]
|
|
||||||
[[ "$output" =~ initial\ private\ dir\ perms\ drwxrwxrwx.+\.gnupg ]]
|
|
||||||
[[ "$output" =~ pre-merge\ private\ dir\ perms\ drwxrwxrwx.+\.ssh ]]
|
|
||||||
[[ "$output" =~ pre-merge\ private\ dir\ perms\ drwxrwxrwx.+\.gnupg ]]
|
|
||||||
[[ "$output" =~ post-merge\ private\ dir\ perms\ drwxrwxrwx.+\.ssh ]]
|
|
||||||
[[ "$output" =~ post-merge\ private\ dir\ perms\ drwxrwxrwx.+\.gnupg ]]
|
|
||||||
# standard perms still apply afterwards unless disabled with auto.perms
|
|
||||||
test_perms "$T_DIR_WORK/.gnupg" "drwx------"
|
|
||||||
test_perms "$T_DIR_WORK/.ssh" "drwx------"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'clone' (local insecure .gnupg data, related data in repo)" {
|
|
||||||
echo "
|
|
||||||
Local .gnupg data exists and is insecure
|
|
||||||
and yadm repo contains .gnupg data
|
|
||||||
.gnupg dir should be secured post merge
|
|
||||||
"
|
|
||||||
#; setup scenario
|
|
||||||
IN_REPO=(.bash_profile .vimrc .gnupg/gpg.conf)
|
|
||||||
setup
|
|
||||||
rm -rf "$T_DIR_WORK" "$T_DIR_REPO"
|
|
||||||
mkdir -p "$T_DIR_WORK/.gnupg"
|
|
||||||
touch "$T_DIR_WORK/.gnupg/testfile"
|
|
||||||
find "$T_DIR_WORK" -exec chmod a+rw '{}' ';'
|
|
||||||
|
|
||||||
#; run clone (with debug on)
|
|
||||||
run "${T_YADM_Y[@]}" clone -d -w "$T_DIR_WORK" "$REMOTE_URL"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Initialized ]]
|
|
||||||
[[ "$output" =~ initial\ private\ dir\ perms\ drwxrwxrwx.+\.gnupg ]]
|
|
||||||
[[ "$output" =~ pre-merge\ private\ dir\ perms\ drwxrwxrwx.+\.gnupg ]]
|
|
||||||
[[ "$output" =~ post-merge\ private\ dir\ perms\ drwxrwxrwx.+\.gnupg ]]
|
|
||||||
test_perms "$T_DIR_WORK/.gnupg" "drwx------"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'clone' (local insecure .ssh data, related data in repo)" {
|
|
||||||
echo "
|
|
||||||
Local .ssh data exists and is insecure
|
|
||||||
and yadm repo contains .ssh data
|
|
||||||
.ssh dir should be secured post merge
|
|
||||||
"
|
|
||||||
#; setup scenario
|
|
||||||
IN_REPO=(.bash_profile .vimrc .ssh/config)
|
|
||||||
setup
|
|
||||||
rm -rf "$T_DIR_WORK" "$T_DIR_REPO"
|
|
||||||
mkdir -p "$T_DIR_WORK/.ssh"
|
|
||||||
touch "$T_DIR_WORK/.ssh/testfile"
|
|
||||||
find "$T_DIR_WORK" -exec chmod a+rw '{}' ';'
|
|
||||||
|
|
||||||
#; run clone (with debug on)
|
|
||||||
run "${T_YADM_Y[@]}" clone -d -w "$T_DIR_WORK" "$REMOTE_URL"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Initialized ]]
|
|
||||||
[[ "$output" =~ initial\ private\ dir\ perms\ drwxrwxrwx.+\.ssh ]]
|
|
||||||
[[ "$output" =~ pre-merge\ private\ dir\ perms\ drwxrwxrwx.+\.ssh ]]
|
|
||||||
[[ "$output" =~ post-merge\ private\ dir\ perms\ drwxrwxrwx.+\.ssh ]]
|
|
||||||
test_perms "$T_DIR_WORK/.ssh" "drwx------"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'clone' (no existing .gnupg, .gnupg data tracked in repo)" {
|
|
||||||
echo "
|
|
||||||
Local .gnupg does not exist
|
|
||||||
and yadm repo contains .gnupg data
|
|
||||||
.gnupg dir should be created and secured prior to merge
|
|
||||||
tracked .gnupg data should be user accessible only
|
|
||||||
"
|
|
||||||
#; setup scenario
|
|
||||||
IN_REPO=(.bash_profile .vimrc .gnupg/gpg.conf)
|
|
||||||
setup
|
|
||||||
rm -rf "$T_DIR_WORK"
|
|
||||||
mkdir -p "$T_DIR_WORK"
|
|
||||||
rm -rf "$T_DIR_REPO"
|
|
||||||
|
|
||||||
#; run clone (with debug on)
|
|
||||||
run "${T_YADM_Y[@]}" clone -d -w "$T_DIR_WORK" "$REMOTE_URL"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Initialized ]]
|
|
||||||
[[ ! "$output" =~ initial\ private\ dir\ perms ]]
|
|
||||||
[[ "$output" =~ pre-merge\ private\ dir\ perms\ drwx------.+\.gnupg ]]
|
|
||||||
[[ "$output" =~ post-merge\ private\ dir\ perms\ drwx------.+\.gnupg ]]
|
|
||||||
test_perms "$T_DIR_WORK/.gnupg" "drwx------"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'clone' (no existing .ssh, .ssh data tracked in repo)" {
|
|
||||||
echo "
|
|
||||||
Local .ssh does not exist
|
|
||||||
and yadm repo contains .ssh data
|
|
||||||
.ssh dir should be created and secured prior to merge
|
|
||||||
tracked .ssh data should be user accessible only
|
|
||||||
"
|
|
||||||
#; setup scenario
|
|
||||||
IN_REPO=(.bash_profile .vimrc .ssh/config)
|
|
||||||
setup
|
|
||||||
rm -rf "$T_DIR_WORK"
|
|
||||||
mkdir -p "$T_DIR_WORK"
|
|
||||||
rm -rf "$T_DIR_REPO"
|
|
||||||
|
|
||||||
#; run clone (with debug on)
|
|
||||||
run "${T_YADM_Y[@]}" clone -d -w "$T_DIR_WORK" "$REMOTE_URL"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Initialized ]]
|
|
||||||
[[ ! "$output" =~ initial\ private\ dir\ perms ]]
|
|
||||||
[[ "$output" =~ pre-merge\ private\ dir\ perms\ drwx------.+\.ssh ]]
|
|
||||||
[[ "$output" =~ post-merge\ private\ dir\ perms\ drwx------.+\.ssh ]]
|
|
||||||
test_perms "$T_DIR_WORK/.ssh" "drwx------"
|
|
||||||
}
|
|
|
@ -1,202 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
T_SECTION="test"
|
|
||||||
T_ATTRIB="attribute"
|
|
||||||
T_KEY="$T_SECTION.$T_ATTRIB"
|
|
||||||
T_VALUE="testvalue"
|
|
||||||
T_EXPECTED="[$T_SECTION]\n\t$T_ATTRIB = $T_VALUE"
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (no parameters)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided alone,
|
|
||||||
Produce instructions about supported configuration options
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run config
|
|
||||||
run "${T_YADM_Y[@]}" config
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ Please\ read\ the\ CONFIGURATION\ section ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (read missing)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided,
|
|
||||||
and an attribute is provided
|
|
||||||
and the attribute isn't configured
|
|
||||||
Report an empty value
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run config
|
|
||||||
run "${T_YADM_Y[@]}" config $T_KEY
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (write)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided,
|
|
||||||
and an attribute is provided
|
|
||||||
and a value is provided
|
|
||||||
Report no output
|
|
||||||
Update configuration file
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run config
|
|
||||||
run "${T_YADM_Y[@]}" config "$T_KEY" "$T_VALUE"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
|
|
||||||
#; validate configuration
|
|
||||||
local config
|
|
||||||
config=$(cat "$T_YADM_CONFIG")
|
|
||||||
local expected
|
|
||||||
expected=$(echo -e "$T_EXPECTED")
|
|
||||||
if [ "$config" != "$expected" ]; then
|
|
||||||
echo "ERROR: Config does not match expected"
|
|
||||||
echo "$config"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (read)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided,
|
|
||||||
and an attribute is provided
|
|
||||||
and the attribute is configured
|
|
||||||
Report the requested value
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually load a value into the configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_EXPECTED" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; run config
|
|
||||||
run "${T_YADM_Y[@]}" config "$T_KEY"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
if [ "$output" != "$T_VALUE" ]; then
|
|
||||||
echo "ERROR: Incorrect value returned. Expected '$T_VALUE', got '$output'"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (update)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided,
|
|
||||||
and an attribute is provided
|
|
||||||
and the attribute is already configured
|
|
||||||
Report no output
|
|
||||||
Update configuration file
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually load a value into the configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "${T_EXPECTED}_with_extra_data" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; run config
|
|
||||||
run "${T_YADM_Y[@]}" config "$T_KEY" "$T_VALUE"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
|
|
||||||
#; validate configuration
|
|
||||||
local config
|
|
||||||
config=$(cat "$T_YADM_CONFIG")
|
|
||||||
local expected
|
|
||||||
expected=$(echo -e "$T_EXPECTED")
|
|
||||||
if [ "$config" != "$expected" ]; then
|
|
||||||
echo "ERROR: Config does not match expected"
|
|
||||||
echo "$config"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (local read)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided,
|
|
||||||
and an attribute is provided
|
|
||||||
and the attribute is configured
|
|
||||||
and the attribute is local.*
|
|
||||||
Fetch the value from the repo config
|
|
||||||
Report the requested value
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; write local attributes
|
|
||||||
build_repo
|
|
||||||
for loption in class os hostname user; do
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config "local.$loption" "custom_$loption"
|
|
||||||
done
|
|
||||||
|
|
||||||
#; run config
|
|
||||||
for loption in class os hostname user; do
|
|
||||||
run "${T_YADM_Y[@]}" config "local.$loption"
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
if [ "$output" != "custom_$loption" ]; then
|
|
||||||
echo "ERROR: Incorrect value returned. Expected 'custom_$loption', got '$output'"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'config' (local write)" {
|
|
||||||
echo "
|
|
||||||
When 'config' command is provided,
|
|
||||||
and an attribute is provided
|
|
||||||
and a value is provided
|
|
||||||
and the attribute is local.*
|
|
||||||
Report no output
|
|
||||||
Write the value to the repo config
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
build_repo
|
|
||||||
local expected
|
|
||||||
local linecount
|
|
||||||
expected="[local]\n"
|
|
||||||
linecount=1
|
|
||||||
for loption in class os hostname user; do
|
|
||||||
#; update expected
|
|
||||||
expected="$expected\t$loption = custom_$loption\n"
|
|
||||||
((linecount+=1))
|
|
||||||
#; write local attributes
|
|
||||||
run "${T_YADM_Y[@]}" config "local.$loption" "custom_$loption"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
done
|
|
||||||
|
|
||||||
#; validate data
|
|
||||||
local config
|
|
||||||
config=$(tail "-$linecount" "$T_DIR_REPO/config")
|
|
||||||
expected=$(echo -ne "$expected")
|
|
||||||
if [ "$config" != "$expected" ]; then
|
|
||||||
echo "ERROR: Config does not match expected"
|
|
||||||
echo -e "$config"
|
|
||||||
echo -e "EXPECTED:\n$expected"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;lines=; #; populated by bats run()
|
|
||||||
|
|
||||||
IN_REPO=(.bash_profile .hammerspoon/init.lua .vimrc)
|
|
||||||
SUBDIR=".hammerspoon"
|
|
||||||
IN_SUBDIR=(init.lua)
|
|
||||||
|
|
||||||
function setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo "${IN_REPO[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'list' -a" {
|
|
||||||
echo "
|
|
||||||
When 'list' command is provided,
|
|
||||||
and '-a' is provided,
|
|
||||||
List tracked files
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run list -a
|
|
||||||
run "${T_YADM_Y[@]}" list -a
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
local line=0
|
|
||||||
for f in "${IN_REPO[@]}"; do
|
|
||||||
[ "${lines[$line]}" = "$f" ]
|
|
||||||
((line++)) || true
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'list' (outside of worktree)" {
|
|
||||||
echo "
|
|
||||||
When 'list' command is provided,
|
|
||||||
and while outside of the worktree
|
|
||||||
List tracked files
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run list
|
|
||||||
run "${T_YADM_Y[@]}" list
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
local line=0
|
|
||||||
for f in "${IN_REPO[@]}"; do
|
|
||||||
[ "${lines[$line]}" = "$f" ]
|
|
||||||
((line++)) || true
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'list' (in root of worktree)" {
|
|
||||||
echo "
|
|
||||||
When 'list' command is provided,
|
|
||||||
and while in root of the worktree
|
|
||||||
List tracked files
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run list
|
|
||||||
run bash -c "(cd '$T_DIR_WORK'; ${T_YADM_Y[*]} list)"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
local line=0
|
|
||||||
for f in "${IN_REPO[@]}"; do
|
|
||||||
[ "${lines[$line]}" = "$f" ]
|
|
||||||
((line++)) || true
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'list' (in subdirectory of worktree)" {
|
|
||||||
echo "
|
|
||||||
When 'list' command is provided,
|
|
||||||
and while in subdirectory of the worktree
|
|
||||||
List tracked files for current directory
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run list
|
|
||||||
run bash -c "(cd '$T_DIR_WORK/$SUBDIR'; ${T_YADM_Y[*]} list)"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
local line=0
|
|
||||||
for f in "${IN_SUBDIR[@]}"; do
|
|
||||||
echo "'${lines[$line]}' = '$f'"
|
|
||||||
[ "${lines[$line]}" = "$f" ]
|
|
||||||
((line++)) || true
|
|
||||||
done
|
|
||||||
}
|
|
|
@ -1,415 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
IN_REPO=(alt* "dir one")
|
|
||||||
export TEST_TREE_WITH_ALT=1
|
|
||||||
EXCLUDED_NAME="excluded-base"
|
|
||||||
|
|
||||||
function create_encrypt() {
|
|
||||||
for efile in "encrypted-base##" "encrypted-system##$T_SYS" "encrypted-host##$T_SYS.$T_HOST" "encrypted-user##$T_SYS.$T_HOST.$T_USER"; do
|
|
||||||
echo "$efile" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo "$efile" >> "$T_DIR_WORK/$efile"
|
|
||||||
mkdir -p "$T_DIR_WORK/dir one/$efile"
|
|
||||||
echo "dir one/$efile/file1" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo "dir one/$efile/file1" >> "$T_DIR_WORK/dir one/$efile/file1"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$EXCLUDED_NAME##" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo "!$EXCLUDED_NAME##" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo "$EXCLUDED_NAME##" >> "$T_DIR_WORK/$EXCLUDED_NAME##"
|
|
||||||
}
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo "${IN_REPO[@]}"
|
|
||||||
create_encrypt
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_alt() {
|
|
||||||
local alt_type="$1"
|
|
||||||
local test_overwrite="$2"
|
|
||||||
local auto_alt="$3"
|
|
||||||
|
|
||||||
#; detemine test parameters
|
|
||||||
case $alt_type in
|
|
||||||
base)
|
|
||||||
link_name="alt-base"
|
|
||||||
link_match="$link_name##"
|
|
||||||
;;
|
|
||||||
system)
|
|
||||||
link_name="alt-system"
|
|
||||||
link_match="$link_name##$T_SYS"
|
|
||||||
;;
|
|
||||||
host)
|
|
||||||
link_name="alt-host"
|
|
||||||
link_match="$link_name##$T_SYS.$T_HOST"
|
|
||||||
;;
|
|
||||||
user)
|
|
||||||
link_name="alt-user"
|
|
||||||
link_match="$link_name##$T_SYS.$T_HOST.$T_USER"
|
|
||||||
;;
|
|
||||||
encrypted_base)
|
|
||||||
link_name="encrypted-base"
|
|
||||||
link_match="$link_name##"
|
|
||||||
;;
|
|
||||||
encrypted_system)
|
|
||||||
link_name="encrypted-system"
|
|
||||||
link_match="$link_name##$T_SYS"
|
|
||||||
;;
|
|
||||||
encrypted_host)
|
|
||||||
link_name="encrypted-host"
|
|
||||||
link_match="$link_name##$T_SYS.$T_HOST"
|
|
||||||
;;
|
|
||||||
encrypted_user)
|
|
||||||
link_name="encrypted-user"
|
|
||||||
link_match="$link_name##$T_SYS.$T_HOST.$T_USER"
|
|
||||||
;;
|
|
||||||
override_system)
|
|
||||||
link_name="alt-override-system"
|
|
||||||
link_match="$link_name##custom_system"
|
|
||||||
;;
|
|
||||||
override_host)
|
|
||||||
link_name="alt-override-host"
|
|
||||||
link_match="$link_name##$T_SYS.custom_host"
|
|
||||||
;;
|
|
||||||
override_user)
|
|
||||||
link_name="alt-override-user"
|
|
||||||
link_match="$link_name##$T_SYS.$T_HOST.custom_user"
|
|
||||||
;;
|
|
||||||
class_aaa)
|
|
||||||
link_name="alt-system"
|
|
||||||
link_match="$link_name##aaa"
|
|
||||||
;;
|
|
||||||
class_zzz)
|
|
||||||
link_name="alt-system"
|
|
||||||
link_match="$link_name##zzz"
|
|
||||||
;;
|
|
||||||
class_AAA)
|
|
||||||
link_name="alt-system"
|
|
||||||
link_match="$link_name##AAA"
|
|
||||||
;;
|
|
||||||
class_ZZZ)
|
|
||||||
link_name="alt-system"
|
|
||||||
link_match="$link_name##ZZZ"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
dir_link_name="dir one/${link_name}"
|
|
||||||
dir_link_match="dir one/${link_match}"
|
|
||||||
|
|
||||||
if [ "$test_overwrite" = "true" ]; then
|
|
||||||
#; create incorrect links (to overwrite)
|
|
||||||
ln -nfs "$T_DIR_WORK/dir2/file2" "$T_DIR_WORK/$link_name"
|
|
||||||
ln -nfs "$T_DIR_WORK/dir2" "$T_DIR_WORK/$dir_link_name"
|
|
||||||
else
|
|
||||||
#; verify link doesn't already exist
|
|
||||||
if [ -L "$T_DIR_WORK/$link_name" ] || [ -L "$T_DIR_WORK/$dir_link_name" ]; then
|
|
||||||
echo "ERROR: Link already exists before running yadm"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; configure yadm.auto_alt=false
|
|
||||||
if [ "$auto_alt" = "false" ]; then
|
|
||||||
git config --file="$T_YADM_CONFIG" yadm.auto-alt false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; run yadm (alt or status)
|
|
||||||
if [ -z "$auto_alt" ]; then
|
|
||||||
run "${T_YADM_Y[@]}" alt
|
|
||||||
#; validate status and output
|
|
||||||
echo "TEST:Link Name:$link_name"
|
|
||||||
echo "TEST:DIR Link Name:$dir_link_name"
|
|
||||||
if [ "$status" != 0 ] || [[ ! "$output" =~ Linking.+$link_name ]] || [[ ! "$output" =~ Linking.+$dir_link_name ]]; then
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
echo "STATUS:$status"
|
|
||||||
echo "ERROR: Could not confirm status and output of alt command"
|
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#; running any passed through Git command should trigger auto-alt
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
if [ -n "$auto_alt" ] && [[ "$output" =~ Linking.+$link_name ]] && [[ "$output" =~ Linking.+$dir_link_name ]]; then
|
|
||||||
echo "ERROR: Reporting of link should not happen"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -L "$T_DIR_WORK/$EXCLUDED_NAME" ] ; then
|
|
||||||
echo "ERROR: Found link: $T_DIR_WORK/$EXCLUDED_NAME"
|
|
||||||
echo "ERROR: Excluded files should not be linked"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; validate link content
|
|
||||||
if [[ "$alt_type" =~ none ]] || [ "$auto_alt" = "false" ]; then
|
|
||||||
#; no link should be present
|
|
||||||
if [ -L "$T_DIR_WORK/$link_name" ] || [ -L "$T_DIR_WORK/$dir_link_name" ]; then
|
|
||||||
echo "ERROR: Links should not exist"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#; correct link should be present
|
|
||||||
local link_content
|
|
||||||
local dir_link_content
|
|
||||||
link_content=$(cat "$T_DIR_WORK/$link_name")
|
|
||||||
dir_link_content=$(cat "$T_DIR_WORK/$dir_link_name/file1")
|
|
||||||
if [ "$link_content" != "$link_match" ] || [ "$dir_link_content" != "$dir_link_match/file1" ]; then
|
|
||||||
echo "link_content: $link_content"
|
|
||||||
echo "dir_link_content: $dir_link_content"
|
|
||||||
echo "ERROR: Link content is not correct"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select base)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select system)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'system' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select host)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM.HOST
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'host' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select user)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM.HOST.USER
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'user' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select none)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and no file matches
|
|
||||||
Verify there is no link
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'none' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select class - aaa)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS - aaa
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class aaa
|
|
||||||
|
|
||||||
test_alt 'class_aaa' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select class - zzz)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS - zzz
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class zzz
|
|
||||||
|
|
||||||
test_alt 'class_zzz' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select class - AAA)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS - AAA
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class AAA
|
|
||||||
|
|
||||||
test_alt 'class_AAA' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select class - ZZZ)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS - ZZZ
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class ZZZ
|
|
||||||
|
|
||||||
test_alt 'class_ZZZ' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'auto-alt' (enabled)" {
|
|
||||||
echo "
|
|
||||||
When a command possibly changes the repo
|
|
||||||
and auto-alt is configured true
|
|
||||||
automatically process alternates
|
|
||||||
report no linking (not loud)
|
|
||||||
verify alternate created
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'false' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'auto-alt' (disabled)" {
|
|
||||||
echo "
|
|
||||||
When a command possibly changes the repo
|
|
||||||
and auto-alt is configured false
|
|
||||||
do no linking
|
|
||||||
verify no links
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'false' 'false'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (overwrite existing link)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and the link exists, and is wrong
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'true' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select encrypted base)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and encrypted file matches only ##
|
|
||||||
Report the linking
|
|
||||||
Verify correct encrypted file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'encrypted_base' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select encrypted system)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and encrypted file matches only ##SYSTEM
|
|
||||||
Report the linking
|
|
||||||
Verify correct encrypted file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'encrypted_system' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select encrypted host)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and encrypted file matches only ##SYSTEM.HOST
|
|
||||||
Report the linking
|
|
||||||
Verify correct encrypted file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'encrypted_host' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select encrypted user)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and encrypted file matches only ##SYSTEM.HOST.USER
|
|
||||||
Report the linking
|
|
||||||
Verify correct encrypted file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'encrypted_user' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select encrypted none)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and no encrypted file matches
|
|
||||||
Verify there is no link
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'encrypted_none' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (override-system)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM
|
|
||||||
after setting local.os
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.os custom_system
|
|
||||||
test_alt 'override_system' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (override-host)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM.HOST
|
|
||||||
after setting local.hostname
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.hostname custom_host
|
|
||||||
test_alt 'override_host' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (override-user)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM.HOST.USER
|
|
||||||
after setting local.user
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.user custom_user
|
|
||||||
test_alt 'override_user' 'false' ''
|
|
||||||
}
|
|
|
@ -1,900 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
T_PASSWD="ExamplePassword"
|
|
||||||
T_ARCHIVE_SYMMETRIC="$T_TMP/build_archive.symmetric"
|
|
||||||
T_ARCHIVE_ASYMMETRIC="$T_TMP/build_archive.asymmetric"
|
|
||||||
T_KEY_NAME="yadm-test1"
|
|
||||||
T_KEY_FINGERPRINT="F8BBFC746C58945442349BCEBA54FFD04C599B1A"
|
|
||||||
T_RECIPIENT_GOOD="[yadm]\n\tgpg-recipient = yadm-test1"
|
|
||||||
T_RECIPIENT_BAD="[yadm]\n\tgpg-recipient = invalid"
|
|
||||||
T_RECIPIENT_ASK="[yadm]\n\tgpg-recipient = ASK"
|
|
||||||
|
|
||||||
#; use gpg1 if it's available
|
|
||||||
T_GPG_PROGRAM="gpg"
|
|
||||||
if command -v gpg1 >/dev/null 2>&1; then
|
|
||||||
T_GPG_PROGRAM="gpg1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
function import_keys() {
|
|
||||||
"$T_GPG_PROGRAM" --import "test/test_key" >/dev/null 2>&1 || true
|
|
||||||
"$T_GPG_PROGRAM" --import-ownertrust < "test/ownertrust.txt" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
function remove_keys() {
|
|
||||||
"$T_GPG_PROGRAM" --batch --yes --delete-secret-keys "$T_KEY_FINGERPRINT" >/dev/null 2>&1 || true
|
|
||||||
"$T_GPG_PROGRAM" --batch --yes --delete-key "$T_KEY_FINGERPRINT" >/dev/null 2>&1 || true
|
|
||||||
}
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
#; start fresh
|
|
||||||
destroy_tmp
|
|
||||||
|
|
||||||
#; import test keys
|
|
||||||
import_keys
|
|
||||||
|
|
||||||
#; create a worktree & repo
|
|
||||||
build_repo
|
|
||||||
|
|
||||||
#; define a YADM_ENCRYPT
|
|
||||||
make_parents "$T_YADM_ENCRYPT"
|
|
||||||
echo -e ".ssh/*.key\n.gnupg/*.gpg" > "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; create a YADM_ARCHIVE
|
|
||||||
(
|
|
||||||
if cd "$T_DIR_WORK"; then
|
|
||||||
# shellcheck disable=2013
|
|
||||||
# (globbing is desired)
|
|
||||||
for f in $(sort "$T_YADM_ENCRYPT"); do
|
|
||||||
tar rf "$T_TMP/build_archive.tar" "$f"
|
|
||||||
echo "$f" >> "$T_TMP/archived_files"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
)
|
|
||||||
|
|
||||||
#; encrypt YADM_ARCHIVE (symmetric)
|
|
||||||
expect <<EOF >/dev/null
|
|
||||||
set timeout 2;
|
|
||||||
spawn "$T_GPG_PROGRAM" --yes -c --output "$T_ARCHIVE_SYMMETRIC" "$T_TMP/build_archive.tar"
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; encrypt YADM_ARCHIVE (asymmetric)
|
|
||||||
"$T_GPG_PROGRAM" --yes --batch -e -r "$T_KEY_NAME" --output "$T_ARCHIVE_ASYMMETRIC" "$T_TMP/build_archive.tar"
|
|
||||||
|
|
||||||
#; configure yadm to use T_GPG_PROGRAM
|
|
||||||
git config --file="$T_YADM_CONFIG" yadm.gpg-program "$T_GPG_PROGRAM"
|
|
||||||
}
|
|
||||||
|
|
||||||
teardown() {
|
|
||||||
remove_keys
|
|
||||||
}
|
|
||||||
|
|
||||||
function validate_archive() {
|
|
||||||
#; inventory what's in the archive
|
|
||||||
if [ "$1" = "symmetric" ]; then
|
|
||||||
expect <<EOF >/dev/null
|
|
||||||
set timeout 2;
|
|
||||||
spawn bash -c "($T_GPG_PROGRAM -q -d '$T_YADM_ARCHIVE' || echo 1) | tar t | sort > $T_TMP/archive_list"
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
"$T_GPG_PROGRAM" -q -d "$T_YADM_ARCHIVE" | tar t | sort > "$T_TMP/archive_list"
|
|
||||||
fi
|
|
||||||
|
|
||||||
excluded="$2"
|
|
||||||
|
|
||||||
#; inventory what is expected in the archive
|
|
||||||
(
|
|
||||||
if cd "$T_DIR_WORK"; then
|
|
||||||
# shellcheck disable=2013
|
|
||||||
# (globbing is desired)
|
|
||||||
while IFS='' read -r glob || [ -n "$glob" ]; do
|
|
||||||
if [[ ! $glob =~ ^# && ! $glob =~ ^[[:space:]]*$ ]] ; then
|
|
||||||
if [[ ! $glob =~ ^!(.+) ]] ; then
|
|
||||||
local IFS=$'\n'
|
|
||||||
for matching_file in $glob; do
|
|
||||||
if [ -e "$matching_file" ]; then
|
|
||||||
if [ "$matching_file" != "$excluded" ]; then
|
|
||||||
if [ -d "$matching_file" ]; then
|
|
||||||
echo "$matching_file/"
|
|
||||||
for subfile in "$matching_file"/*; do
|
|
||||||
echo "$subfile"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo "$matching_file"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done < "$T_YADM_ENCRYPT" | sort > "$T_TMP/expected_list"
|
|
||||||
fi
|
|
||||||
)
|
|
||||||
|
|
||||||
#; compare the archive vs expected
|
|
||||||
if ! cmp -s "$T_TMP/archive_list" "$T_TMP/expected_list"; then
|
|
||||||
echo "ERROR: Archive does not contain the correct files"
|
|
||||||
echo "Contains:"
|
|
||||||
cat "$T_TMP/archive_list"
|
|
||||||
echo "Expected:"
|
|
||||||
cat "$T_TMP/expected_list"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function validate_extraction() {
|
|
||||||
#; test each file which was archived
|
|
||||||
while IFS= read -r f; do
|
|
||||||
local contents
|
|
||||||
contents=$(cat "$T_DIR_WORK/$f")
|
|
||||||
if [ "$contents" != "$f" ]; then
|
|
||||||
echo "ERROR: Contents of $T_DIR_WORK/$f is incorrect"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done < "$T_TMP/archived_files"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (missing YADM_ENCRYPT)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT does not exist
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; remove YADM_ENCRYPT
|
|
||||||
rm -f "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run "${T_YADM_Y[@]}" encrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ does\ not\ exist ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (mismatched password)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
and the provided passwords do not match
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "ONE\n"}
|
|
||||||
expect "passphrase:" {send "TWO\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ invalid\ passphrase ]]
|
|
||||||
[[ "$output" =~ Unable\ to\ write ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt'" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (comments in YADM_ENCRYPT)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; add comment to YADM_ARCHIVE
|
|
||||||
local original_encrypt
|
|
||||||
original_encrypt=$(cat "$T_YADM_ENCRYPT")
|
|
||||||
echo -e "#.vimrc" >> "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; restore comment-free version before valiation
|
|
||||||
echo "$original_encrypt" > "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (empty lines and space lines in YADM_ENCRYPT)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; add empty lines to YADM_ARCHIVE
|
|
||||||
local original_encrypt
|
|
||||||
original_encrypt=$(cat "$T_YADM_ENCRYPT")
|
|
||||||
echo -e " \n\n \n" >> "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; restore empty-line-free version before valiation
|
|
||||||
echo "$original_encrypt" > "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (paths with spaces/globs in YADM_ENCRYPT)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; add paths with spaces to YADM_ARCHIVE
|
|
||||||
local original_encrypt
|
|
||||||
original_encrypt=$(cat "$T_YADM_ENCRYPT")
|
|
||||||
echo -e "space test/file*" >> "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (exclusions in YADM_ENCRYPT)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; add paths with spaces to YADM_ARCHIVE
|
|
||||||
local original_encrypt
|
|
||||||
original_encrypt=$(cat "$T_YADM_ENCRYPT")
|
|
||||||
echo -e ".ssh/*" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo -e "!.ssh/sec*.pub" >> "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
[[ ! "$output" =~ \.ssh/secret.pub ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric ".ssh/secret.pub"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (directories in YADM_ENCRYPT)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; add directory paths to YADM_ARCHIVE
|
|
||||||
local original_encrypt
|
|
||||||
original_encrypt=$(cat "$T_YADM_ENCRYPT")
|
|
||||||
echo -e "space test" >> "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (overwrite)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
and YADM_ARCHIVE already exists
|
|
||||||
Overwrite YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; Explicitly create an invalid archive
|
|
||||||
echo "EXISTING ARCHIVE" > "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive symmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (missing YADM_ARCHIVE)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and YADM_ARCHIVE does not exist
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ does\ not\ exist ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (wrong password)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
and the provided password is wrong
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; use the symmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_SYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} decrypt;
|
|
||||||
expect "passphrase:" {send "WRONG\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ decryption\ failed ]]
|
|
||||||
[[ "$output" =~ Unable\ to\ extract ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' -l (wrong password)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and '-l' is provided,
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
and the provided password is wrong
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; use the symmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_SYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} decrypt -l;
|
|
||||||
expect "passphrase:" {send "WRONG\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ decryption\ failed ]]
|
|
||||||
[[ "$output" =~ Unable\ to\ extract ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt'" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
Report the data created
|
|
||||||
Data should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; use the symmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_SYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; empty the worktree
|
|
||||||
rm -rf "$T_DIR_WORK"
|
|
||||||
mkdir -p "$T_DIR_WORK"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} decrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ All\ files\ decrypted ]]
|
|
||||||
|
|
||||||
#; validate the extracted files
|
|
||||||
validate_extraction
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (overwrite)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
and archived content already exists
|
|
||||||
Report the data overwritten
|
|
||||||
Data should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; use the symmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_SYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; alter the values of the archived files
|
|
||||||
while IFS= read -r f; do
|
|
||||||
echo "changed" >> "$T_DIR_WORK/$f"
|
|
||||||
done < "$T_TMP/archived_files"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} decrypt;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ All\ files\ decrypted ]]
|
|
||||||
|
|
||||||
#; validate the extracted files
|
|
||||||
validate_extraction
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' -l" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and '-l' is provided,
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
Report the contents of YADM_ARCHIVE
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; use the symmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_SYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} decrypt -l;
|
|
||||||
expect "passphrase:" {send "$T_PASSWD\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
|
|
||||||
#; validate every file is listed in output
|
|
||||||
while IFS= read -r f; do
|
|
||||||
if [[ ! "$output" =~ $f ]]; then
|
|
||||||
echo "ERROR: Did not find '$f' in output"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done < "$T_TMP/archived_files"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (asymmetric, missing key)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
and yadm.gpg-recipient refers to an invalid private key
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_BAD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run "${T_YADM_Y[@]}" encrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ public\ key\ not\ found ]] || [[ "$output" =~ No\ public\ key ]]
|
|
||||||
[[ "$output" =~ Unable\ to\ write ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (asymmetric)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run "${T_YADM_Y[@]}" encrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive asymmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (asymmetric, overwrite)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE already exists
|
|
||||||
Overwrite YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; Explicitly create an invalid archive
|
|
||||||
echo "EXISTING ARCHIVE" > "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run "${T_YADM_Y[@]}" encrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive asymmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'encrypt' (asymmetric, ask)" {
|
|
||||||
echo "
|
|
||||||
When 'encrypt' command is provided,
|
|
||||||
and YADM_ENCRYPT is present
|
|
||||||
and yadm.gpg-recipient is set to ASK
|
|
||||||
Ask for recipient
|
|
||||||
Create YADM_ARCHIVE
|
|
||||||
Report the archive created
|
|
||||||
Archive should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_ASK" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; run encrypt
|
|
||||||
run expect <<EOF
|
|
||||||
set timeout 2;
|
|
||||||
spawn ${T_YADM_Y[*]} encrypt;
|
|
||||||
expect "Enter the user ID" {send "$T_KEY_NAME\n\n"}
|
|
||||||
expect "$"
|
|
||||||
foreach {pid spawnid os_error_flag value} [wait] break
|
|
||||||
exit \$value
|
|
||||||
EOF
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ Wrote\ new\ file:.+$T_YADM_ARCHIVE ]]
|
|
||||||
|
|
||||||
#; validate the archive
|
|
||||||
validate_archive asymmetric
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (asymmetric, missing YADM_ARCHIVE)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE does not exist
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ does\ not\ exist ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (asymmetric, missing key)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
and the private key is not present
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; use the asymmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_ASYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; remove the private key
|
|
||||||
remove_keys
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ decryption\ failed ]]
|
|
||||||
[[ "$output" =~ Unable\ to\ extract ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' -l (asymmetric, missing key)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and '-l' is provided,
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
and the private key is not present
|
|
||||||
Report problem
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; use the asymmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_ASYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; remove the private key
|
|
||||||
remove_keys
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
[[ "$output" =~ decryption\ failed ]]
|
|
||||||
[[ "$output" =~ Unable\ to\ extract ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (asymmetric)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
Report the data created
|
|
||||||
Data should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; use the asymmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_ASYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; empty the worktree
|
|
||||||
rm -rf "$T_DIR_WORK"
|
|
||||||
mkdir -p "$T_DIR_WORK"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ All\ files\ decrypted ]]
|
|
||||||
|
|
||||||
#; validate the extracted files
|
|
||||||
validate_extraction
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' (asymmetric, overwrite)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
and archived content already exists
|
|
||||||
Report the data overwritten
|
|
||||||
Data should be valid
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; use the asymmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_ASYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; alter the values of the archived files
|
|
||||||
while IFS= read -r f; do
|
|
||||||
echo "changed" >> "$T_DIR_WORK/$f"
|
|
||||||
done < "$T_TMP/archived_files"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ All\ files\ decrypted ]]
|
|
||||||
|
|
||||||
#; validate the extracted files
|
|
||||||
validate_extraction
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'decrypt' -l (asymmetric)" {
|
|
||||||
echo "
|
|
||||||
When 'decrypt' command is provided,
|
|
||||||
and '-l' is provided,
|
|
||||||
and yadm.gpg-recipient refers to a valid private key
|
|
||||||
and YADM_ARCHIVE is present
|
|
||||||
Report the contents of YADM_ARCHIVE
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; manually set yadm.gpg-recipient in configuration
|
|
||||||
make_parents "$T_YADM_CONFIG"
|
|
||||||
echo -e "$T_RECIPIENT_GOOD" > "$T_YADM_CONFIG"
|
|
||||||
|
|
||||||
#; use the asymmetric archive
|
|
||||||
cp -f "$T_ARCHIVE_ASYMMETRIC" "$T_YADM_ARCHIVE"
|
|
||||||
|
|
||||||
#; run decrypt
|
|
||||||
run "${T_YADM_Y[@]}" decrypt -l
|
|
||||||
|
|
||||||
#; validate status
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
|
|
||||||
#; validate every file is listed in output
|
|
||||||
while IFS= read -r f; do
|
|
||||||
if [[ ! "$output" =~ $f ]]; then
|
|
||||||
echo "ERROR: Did not find '$f' in output"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done < "$T_TMP/archived_files"
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,173 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_restricted() {
|
|
||||||
local p
|
|
||||||
for p in "${restricted[@]}"; do [ "$p" = "$1" ] && return 0; done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function validate_perms() {
|
|
||||||
local perms="$*"
|
|
||||||
|
|
||||||
#; determine which paths should have restricted permissions
|
|
||||||
restricted=()
|
|
||||||
local p
|
|
||||||
for p in $perms; do
|
|
||||||
case $p in
|
|
||||||
ssh)
|
|
||||||
restricted=("${restricted[@]}" $T_DIR_WORK/.ssh $T_DIR_WORK/.ssh/*)
|
|
||||||
;;
|
|
||||||
gpg)
|
|
||||||
restricted=("${restricted[@]}" $T_DIR_WORK/.gnupg $T_DIR_WORK/.gnupg/*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
restricted=("${restricted[@]}" $T_DIR_WORK/$p)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
#; validate permissions of each path in the worktere
|
|
||||||
local testpath
|
|
||||||
while IFS= read -r -d '' testpath; do
|
|
||||||
local perm_regex="....rwxrwx"
|
|
||||||
if is_restricted "$testpath"; then
|
|
||||||
perm_regex="....------"
|
|
||||||
fi
|
|
||||||
test_perms "$testpath" "$perm_regex" || return 1
|
|
||||||
done < <(find "$T_DIR_WORK" -print0)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'perms'" {
|
|
||||||
echo "
|
|
||||||
When the command 'perms' is provided
|
|
||||||
Update permissions for ssh/gpg
|
|
||||||
Verify correct permissions
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run perms
|
|
||||||
run "${T_YADM_Y[@]}" perms
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
|
|
||||||
#; validate permissions
|
|
||||||
validate_perms ssh gpg
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'perms' (with encrypt)" {
|
|
||||||
echo "
|
|
||||||
When the command 'perms' is provided
|
|
||||||
And YADM_ENCRYPT is present
|
|
||||||
Update permissions for ssh/gpg/encrypt
|
|
||||||
Support comments in YADM_ENCRYPT
|
|
||||||
Verify correct permissions
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; this version has a comment in it
|
|
||||||
echo -e "#.vimrc\n.tmux.conf\n.hammerspoon/*\n!.tmux.conf" > "$T_YADM_ENCRYPT"
|
|
||||||
|
|
||||||
#; run perms
|
|
||||||
run "${T_YADM_Y[@]}" perms
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
|
|
||||||
#; validate permissions
|
|
||||||
validate_perms ssh gpg ".hammerspoon/*"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'perms' (ssh-perms=false)" {
|
|
||||||
echo "
|
|
||||||
When the command 'perms' is provided
|
|
||||||
And yadm.ssh-perms=false
|
|
||||||
Update permissions for gpg only
|
|
||||||
Verify correct permissions
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; configure yadm.ssh-perms
|
|
||||||
git config --file="$T_YADM_CONFIG" "yadm.ssh-perms" "false"
|
|
||||||
|
|
||||||
#; run perms
|
|
||||||
run "${T_YADM_Y[@]}" perms
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
|
|
||||||
#; validate permissions
|
|
||||||
validate_perms gpg
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'perms' (gpg-perms=false)" {
|
|
||||||
echo "
|
|
||||||
When the command 'perms' is provided
|
|
||||||
And yadm.gpg-perms=false
|
|
||||||
Update permissions for ssh only
|
|
||||||
Verify correct permissions
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; configure yadm.gpg-perms
|
|
||||||
git config --file="$T_YADM_CONFIG" "yadm.gpg-perms" "false"
|
|
||||||
|
|
||||||
#; run perms
|
|
||||||
run "${T_YADM_Y[@]}" perms
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[ "$output" = "" ]
|
|
||||||
|
|
||||||
#; validate permissions
|
|
||||||
validate_perms ssh
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'auto-perms' (enabled)" {
|
|
||||||
echo "
|
|
||||||
When a command possibly changes the repo
|
|
||||||
Update permissions for ssh/gpg
|
|
||||||
Verify correct permissions
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run status
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
|
|
||||||
#; validate status
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
|
|
||||||
#; validate permissions
|
|
||||||
validate_perms ssh gpg
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'auto-perms' (disabled)" {
|
|
||||||
echo "
|
|
||||||
When a command possibly changes the repo
|
|
||||||
And yadm.auto-perms=false
|
|
||||||
Take no action
|
|
||||||
Verify permissions are intact
|
|
||||||
"
|
|
||||||
|
|
||||||
#; configure yadm.auto-perms
|
|
||||||
git config --file="$T_YADM_CONFIG" "yadm.auto-perms" "false"
|
|
||||||
|
|
||||||
#; run status
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
|
|
||||||
#; validate status
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
|
|
||||||
#; validate permissions
|
|
||||||
validate_perms
|
|
||||||
}
|
|
|
@ -1,223 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
IN_REPO=(wild*)
|
|
||||||
export TEST_TREE_WITH_WILD=1
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo "${IN_REPO[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_alt() {
|
|
||||||
local link_name="$1"
|
|
||||||
local link_match="$2"
|
|
||||||
|
|
||||||
#; run yadm alt
|
|
||||||
run "${T_YADM_Y[@]}" alt
|
|
||||||
#; validate status and output
|
|
||||||
if [ "$status" != 0 ] || [[ ! "$output" =~ Linking.+$link_name ]]; then
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
echo "ERROR: Could not confirm status and output of alt command"
|
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; correct link should be present
|
|
||||||
local link_content
|
|
||||||
link_content=$(cat "$T_DIR_WORK/$link_name")
|
|
||||||
if [ "$link_content" != "$link_match" ]; then
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
echo "ERROR: Link content is not correct"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild none)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'wild-none' 'wild-none##'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild system)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
for WILD_S in 'local' 'wild'; do
|
|
||||||
local s_base="wild-system-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
local match="${s_base}##${WILD_S}"
|
|
||||||
echo test_alt "$s_base" "$match"
|
|
||||||
test_alt "$s_base" "$match"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild class)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
|
||||||
local c_base="wild-class-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
local match="${c_base}##${WILD_C}"
|
|
||||||
echo test_alt "$c_base" "$match"
|
|
||||||
test_alt "$c_base" "$match"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild host)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM.HOST
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
for WILD_S in 'local' 'wild'; do
|
|
||||||
local s_base="wild-host-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
local match="${h_base}##${WILD_S}.${WILD_H}"
|
|
||||||
echo test_alt "$h_base" "$match"
|
|
||||||
test_alt "$h_base" "$match"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild class-system)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS.SYSTEM
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
|
||||||
local c_base="wild-class-system-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
for WILD_S in 'local' 'wild'; do
|
|
||||||
local s_base="${c_base}-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
local match="${s_base}##${WILD_C}.${WILD_S}"
|
|
||||||
echo test_alt "$s_base" "$match"
|
|
||||||
test_alt "$s_base" "$match"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild user)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##SYSTEM.HOST.USER
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
for WILD_S in 'local' 'wild'; do
|
|
||||||
local s_base="wild-user-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
for WILD_U in 'local' 'wild'; do
|
|
||||||
local u_base="${h_base}-$WILD_U"
|
|
||||||
case $WILD_U in local) WILD_U="$T_USER";; wild) WILD_U="%";; esac
|
|
||||||
local match="${u_base}##${WILD_S}.${WILD_H}.${WILD_U}"
|
|
||||||
echo test_alt "$u_base" "$match"
|
|
||||||
test_alt "$u_base" "$match"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild class-system-host)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS.SYSTEM.HOST
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
|
||||||
local c_base="wild-class-system-host-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
for WILD_S in 'local' 'wild'; do
|
|
||||||
local s_base="${c_base}-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
local match="${h_base}##${WILD_C}.${WILD_S}.${WILD_H}"
|
|
||||||
echo test_alt "$h_base" "$match"
|
|
||||||
test_alt "$h_base" "$match"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (wild class-system-host-user)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches only ##CLASS.SYSTEM.HOST.USER
|
|
||||||
with possible wildcards
|
|
||||||
Report the linking
|
|
||||||
Verify correct file is linked
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
|
||||||
local c_base="wild-class-system-host-user-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
for WILD_S in 'local' 'wild'; do
|
|
||||||
local s_base="${c_base}-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
for WILD_U in 'local' 'wild'; do
|
|
||||||
local u_base="${h_base}-$WILD_U"
|
|
||||||
case $WILD_U in local) WILD_U="$T_USER";; wild) WILD_U="%";; esac
|
|
||||||
local match="${u_base}##${WILD_C}.${WILD_S}.${WILD_H}.${WILD_U}"
|
|
||||||
echo test_alt "$u_base" "$match"
|
|
||||||
test_alt "$u_base" "$match"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'bootstrap' (missing file)" {
|
|
||||||
echo "
|
|
||||||
When 'bootstrap' command is provided,
|
|
||||||
and the bootstrap file is missing
|
|
||||||
Report error
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run clone
|
|
||||||
run "${T_YADM_Y[@]}" bootstrap
|
|
||||||
echo "STATUS:$status"
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[[ "$output" =~ Cannot\ execute\ bootstrap ]]
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'bootstrap' (not executable)" {
|
|
||||||
echo "
|
|
||||||
When 'bootstrap' command is provided,
|
|
||||||
and the bootstrap file is present
|
|
||||||
but is not executable
|
|
||||||
Report error
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
touch "$T_YADM_BOOTSTRAP"
|
|
||||||
|
|
||||||
#; run clone
|
|
||||||
run "${T_YADM_Y[@]}" bootstrap
|
|
||||||
echo "STATUS:$status"
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[[ "$output" =~ is\ not\ an\ executable\ program ]]
|
|
||||||
[ "$status" -eq 1 ]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'bootstrap' (bootstrap run)" {
|
|
||||||
echo "
|
|
||||||
When 'bootstrap' command is provided,
|
|
||||||
and the bootstrap file is present
|
|
||||||
and is executable
|
|
||||||
Announce the execution
|
|
||||||
Execute bootstrap
|
|
||||||
Exit with the exit code of bootstrap
|
|
||||||
"
|
|
||||||
|
|
||||||
{
|
|
||||||
echo "#!/bin/bash"
|
|
||||||
echo "echo Bootstrap successful"
|
|
||||||
echo "exit 123"
|
|
||||||
} > "$T_YADM_BOOTSTRAP"
|
|
||||||
chmod a+x "$T_YADM_BOOTSTRAP"
|
|
||||||
|
|
||||||
#; run clone
|
|
||||||
run "${T_YADM_Y[@]}" bootstrap
|
|
||||||
echo "STATUS:$status"
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[[ "$output" =~ Executing\ $T_YADM_BOOTSTRAP ]]
|
|
||||||
[[ "$output" =~ Bootstrap\ successful ]]
|
|
||||||
[ "$status" -eq 123 ]
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,203 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
IN_REPO=(alt* "dir one")
|
|
||||||
export TEST_TREE_WITH_ALT=1
|
|
||||||
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo "${IN_REPO[@]}"
|
|
||||||
echo "excluded-encrypt##yadm.j2" > "$T_YADM_ENCRYPT"
|
|
||||||
echo "included-encrypt##yadm.j2" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo "!excluded-encrypt*" >> "$T_YADM_ENCRYPT"
|
|
||||||
echo "included-encrypt" > "$T_DIR_WORK/included-encrypt##yadm.j2"
|
|
||||||
echo "excluded-encrypt" > "$T_DIR_WORK/excluded-encrypt##yadm.j2"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function test_alt() {
|
|
||||||
local alt_type="$1"
|
|
||||||
local test_overwrite="$2"
|
|
||||||
local auto_alt="$3"
|
|
||||||
|
|
||||||
#; detemine test parameters
|
|
||||||
case $alt_type in
|
|
||||||
base)
|
|
||||||
real_name="alt-jinja"
|
|
||||||
file_content_match="-${T_SYS}-${T_HOST}-${T_USER}-${T_DISTRO}"
|
|
||||||
;;
|
|
||||||
override_all)
|
|
||||||
real_name="alt-jinja"
|
|
||||||
file_content_match="custom_class-custom_system-custom_host-custom_user-${T_DISTRO}"
|
|
||||||
;;
|
|
||||||
encrypt)
|
|
||||||
real_name="included-encrypt"
|
|
||||||
file_content_match="included-encrypt"
|
|
||||||
missing_name="excluded-encrypt"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ "$test_overwrite" = "true" ] ; then
|
|
||||||
#; create incorrect links (to overwrite)
|
|
||||||
echo "BAD_CONTENT" "$T_DIR_WORK/$real_name"
|
|
||||||
else
|
|
||||||
#; verify real file doesn't already exist
|
|
||||||
if [ -e "$T_DIR_WORK/$real_name" ] ; then
|
|
||||||
echo "ERROR: real file already exists before running yadm"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; configure yadm.auto_alt=false
|
|
||||||
if [ "$auto_alt" = "false" ]; then
|
|
||||||
git config --file="$T_YADM_CONFIG" yadm.auto-alt false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; run yadm (alt or status)
|
|
||||||
if [ -z "$auto_alt" ]; then
|
|
||||||
run "${T_YADM_Y[@]}" alt
|
|
||||||
#; validate status and output
|
|
||||||
if [ "$status" != 0 ] || [[ ! "$output" =~ Creating.+$real_name ]]; then
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
echo "ERROR: Could not confirm status and output of alt command"
|
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#; running any passed through Git command should trigger auto-alt
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
if [ -n "$auto_alt" ] && [[ "$output" =~ Creating.+$real_name ]]; then
|
|
||||||
echo "ERROR: Reporting of jinja processing should not happen"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$missing_name" ] && [ -f "$T_DIR_WORK/$missing_name" ]; then
|
|
||||||
echo "ERROR: File should not have been created '$missing_name'"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; validate link content
|
|
||||||
if [[ "$alt_type" =~ none ]] || [ "$auto_alt" = "false" ]; then
|
|
||||||
#; no real file should be present
|
|
||||||
if [ -L "$T_DIR_WORK/$real_name" ] ; then
|
|
||||||
echo "ERROR: Real file should not exist"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#; correct real file should be present
|
|
||||||
local file_content
|
|
||||||
file_content=$(cat "$T_DIR_WORK/$real_name")
|
|
||||||
if [ "$file_content" != "$file_content_match" ]; then
|
|
||||||
echo "file_content: ${file_content}"
|
|
||||||
echo "expected_content: ${file_content_match}"
|
|
||||||
echo "ERROR: Link content is not correct"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (envtpl missing)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches ##yadm.j2
|
|
||||||
Report jinja template as unprocessed
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
YADM_TEST=1 source "$T_YADM"
|
|
||||||
process_global_args -Y "$T_DIR_YADM"
|
|
||||||
set_operating_system
|
|
||||||
configure_paths
|
|
||||||
|
|
||||||
status=0
|
|
||||||
output=$( ENVTPL_PROGRAM='envtpl_missing' main alt ) || {
|
|
||||||
status=$?
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ envtpl.not.available ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select jinja)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches ##yadm.j2
|
|
||||||
Report jinja template processing
|
|
||||||
Verify that the correct content is written
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'auto-alt' (enabled)" {
|
|
||||||
echo "
|
|
||||||
When a command possibly changes the repo
|
|
||||||
and auto-alt is configured true
|
|
||||||
and file matches ##yadm.j2
|
|
||||||
automatically process alternates
|
|
||||||
report no linking (not loud)
|
|
||||||
Verify that the correct content is written
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'false' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'auto-alt' (disabled)" {
|
|
||||||
echo "
|
|
||||||
When a command possibly changes the repo
|
|
||||||
and auto-alt is configured false
|
|
||||||
and file matches ##yadm.j2
|
|
||||||
Report no jinja template processing
|
|
||||||
Verify no content
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'false' 'false'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (overwrite existing content)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches ##yadm.j2
|
|
||||||
and the real file exists, and is wrong
|
|
||||||
Report jinja template processing
|
|
||||||
Verify that the correct content is written
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'base' 'true' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (overwritten settings)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches ##yadm.j2
|
|
||||||
after setting local.*
|
|
||||||
Report jinja template processing
|
|
||||||
Verify that the correct content is written
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.os custom_system
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.user custom_user
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.hostname custom_host
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config local.class custom_class
|
|
||||||
test_alt 'override_all' 'false' ''
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'alt' (select jinja within .yadm/encrypt)" {
|
|
||||||
echo "
|
|
||||||
When the command 'alt' is provided
|
|
||||||
and file matches ##yadm.j2 within .yadm/encrypt
|
|
||||||
and file excluded within .yadm/encrypt
|
|
||||||
Report jinja template processing
|
|
||||||
Verify that the correct content is written
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
test_alt 'encrypt' 'false' ''
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
build_repo
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'enter' (SHELL not set)" {
|
|
||||||
echo "
|
|
||||||
When 'enter' command is provided,
|
|
||||||
And SHELL is not set
|
|
||||||
Report error
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
SHELL=
|
|
||||||
export SHELL
|
|
||||||
run "${T_YADM_Y[@]}" enter
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 1 ]
|
|
||||||
[[ "$output" =~ does.not.refer.to.an.executable ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'enter' (SHELL not executable)" {
|
|
||||||
echo "
|
|
||||||
When 'enter' command is provided,
|
|
||||||
And SHELL is not executable
|
|
||||||
Report error
|
|
||||||
Exit with 1
|
|
||||||
"
|
|
||||||
|
|
||||||
touch "$T_TMP/badshell"
|
|
||||||
SHELL="$T_TMP/badshell"
|
|
||||||
export SHELL
|
|
||||||
run "${T_YADM_Y[@]}" enter
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 1 ]
|
|
||||||
[[ "$output" =~ does.not.refer.to.an.executable ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'enter' (SHELL executable)" {
|
|
||||||
echo "
|
|
||||||
When 'enter' command is provided,
|
|
||||||
And SHELL is set
|
|
||||||
Execute SHELL command
|
|
||||||
Expose GIT variables
|
|
||||||
Set prompt variables
|
|
||||||
Announce entering/leaving shell
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
SHELL=$(command -v env)
|
|
||||||
export SHELL
|
|
||||||
run "${T_YADM_Y[@]}" enter
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ GIT_DIR= ]]
|
|
||||||
[[ "$output" =~ PROMPT=yadm.shell ]]
|
|
||||||
[[ "$output" =~ PS1=yadm.shell ]]
|
|
||||||
[[ "$output" =~ Entering.yadm.repo ]]
|
|
||||||
[[ "$output" =~ Leaving.yadm.repo ]]
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
function count_introspect() {
|
|
||||||
local category="$1"
|
|
||||||
local expected_status="$2"
|
|
||||||
local expected_words="$3"
|
|
||||||
local expected_regex="$4"
|
|
||||||
|
|
||||||
run "${T_YADM_Y[@]}" introspect "$category"
|
|
||||||
local output_words
|
|
||||||
output_words=$(wc -w <<< "$output")
|
|
||||||
|
|
||||||
if [ "$status" -ne "$expected_status" ]; then
|
|
||||||
echo "ERROR: Unexpected exit code (expected $expected_status, got $status)"
|
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$output_words" -ne "$expected_words" ]; then
|
|
||||||
echo "ERROR: Unexpected number of output words (expected $expected_words, got $output_words)"
|
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$expected_regex" ]; then
|
|
||||||
if [[ ! "$output" =~ $expected_regex ]]; then
|
|
||||||
echo "OUTPUT:$output"
|
|
||||||
echo "ERROR: Output does not match regex: $expected_regex"
|
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'introspect' (no category)" {
|
|
||||||
echo "
|
|
||||||
When 'introspect' command is provided,
|
|
||||||
And no category is provided
|
|
||||||
Produce no output
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
count_introspect "" 0 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'introspect' (invalid category)" {
|
|
||||||
echo "
|
|
||||||
When 'introspect' command is provided,
|
|
||||||
And an invalid category is provided
|
|
||||||
Produce no output
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
count_introspect "invalid_cat" 0 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'introspect' (commands)" {
|
|
||||||
echo "
|
|
||||||
When 'introspect' command is provided,
|
|
||||||
And category 'commands' is provided
|
|
||||||
Produce command list
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
count_introspect "commands" 0 15 'version'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'introspect' (configs)" {
|
|
||||||
echo "
|
|
||||||
When 'introspect' command is provided,
|
|
||||||
And category 'configs' is provided
|
|
||||||
Produce switch list
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
count_introspect "configs" 0 13 'yadm\.auto-alt'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'introspect' (repo)" {
|
|
||||||
echo "
|
|
||||||
When 'introspect' command is provided,
|
|
||||||
And category 'repo' is provided
|
|
||||||
Output repo
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
count_introspect "repo" 0 1 "$T_DIR_REPO"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Command 'introspect' (switches)" {
|
|
||||||
echo "
|
|
||||||
When 'introspect' command is provided,
|
|
||||||
And category 'switches' is provided
|
|
||||||
Produce switch list
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
count_introspect "switches" 0 7 '--yadm-dir'
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
IN_REPO=(alt*)
|
|
||||||
export TEST_TREE_WITH_CYGWIN=1
|
|
||||||
export SIMULATED_CYGWIN="CYGWIN_NT-6.1-WOW64"
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo "${IN_REPO[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_alt() {
|
|
||||||
local cygwin_copy="$1"
|
|
||||||
local is_cygwin="$2"
|
|
||||||
local expect_link="$3"
|
|
||||||
local preexisting_link="$4"
|
|
||||||
|
|
||||||
case "$cygwin_copy" in
|
|
||||||
true|false)
|
|
||||||
git config --file="$T_YADM_CONFIG" "yadm.cygwin-copy" "$cygwin_copy"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ "$is_cygwin" = "true" ]; then
|
|
||||||
echo '#!/bin/sh' > "$T_TMP/uname"
|
|
||||||
echo "echo $SIMULATED_CYGWIN" >> "$T_TMP/uname"
|
|
||||||
chmod a+x "$T_TMP/uname"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local expected_content
|
|
||||||
expected_content="$T_DIR_WORK/alt-test##$(PATH="$T_TMP:$PATH" uname -s)"
|
|
||||||
|
|
||||||
if [ "$preexisting_link" = 'symlink' ]; then
|
|
||||||
ln -s "$expected_content" "$T_DIR_WORK/alt-test"
|
|
||||||
elif [ "$preexisting_link" = 'file' ]; then
|
|
||||||
touch "$T_DIR_WORK/alt-test"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PATH="$T_TMP:$PATH" run "${T_YADM_Y[@]}" alt
|
|
||||||
|
|
||||||
echo "Alt output:$output"
|
|
||||||
echo "Alt status:$status"
|
|
||||||
|
|
||||||
if [ -L "$T_DIR_WORK/alt-test" ] && [ "$expect_link" != 'true' ] ; then
|
|
||||||
echo "ERROR: Alt should be a simple file, but isn't"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [ ! -L "$T_DIR_WORK/alt-test" ] && [ "$expect_link" = 'true' ] ; then
|
|
||||||
echo "ERROR: Alt should use symlink, but doesn't"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! diff "$T_DIR_WORK/alt-test" "$expected_content"; then
|
|
||||||
echo "ERROR: Alt contains different data than expected"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (unset, non-cygwin)" {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is unset
|
|
||||||
and the OS is not CYGWIN
|
|
||||||
Verify alternate is a symlink
|
|
||||||
"
|
|
||||||
test_alt 'unset' 'false' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (true, non-cygwin)" {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is true
|
|
||||||
and the OS is not CYGWIN
|
|
||||||
Verify alternate is a symlink
|
|
||||||
"
|
|
||||||
test_alt 'true' 'false' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (false, non-cygwin)" {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is false
|
|
||||||
and the OS is not CYGWIN
|
|
||||||
Verify alternate is a symlink
|
|
||||||
"
|
|
||||||
test_alt 'false' 'false' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (unset, cygwin)" {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is unset
|
|
||||||
and the OS is CYGWIN
|
|
||||||
Verify alternate is a symlink
|
|
||||||
"
|
|
||||||
test_alt 'unset' 'true' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (true, cygwin)" {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is true
|
|
||||||
and the OS is CYGWIN
|
|
||||||
Verify alternate is a copy
|
|
||||||
"
|
|
||||||
test_alt 'true' 'true' 'false'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (false, cygwin)" {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is false
|
|
||||||
and the OS is CYGWIN
|
|
||||||
Verify alternate is a symlink
|
|
||||||
"
|
|
||||||
test_alt 'false' 'true' 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (preexisting symlink) " {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is true
|
|
||||||
and the OS is CYGWIN
|
|
||||||
Verify alternate is a copy
|
|
||||||
"
|
|
||||||
test_alt 'true' 'true' 'false' 'symlink'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Option 'yadm.cygwin-copy' (preexisting file) " {
|
|
||||||
echo "
|
|
||||||
When the option 'yadm.cygwin-copy' is true
|
|
||||||
and the OS is CYGWIN
|
|
||||||
Verify alternate is a copy
|
|
||||||
"
|
|
||||||
test_alt 'true' 'true' 'false' 'file'
|
|
||||||
}
|
|
|
@ -1,181 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
version_regex="yadm [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo
|
|
||||||
mkdir -p "$T_DIR_HOOKS"
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_hook() {
|
|
||||||
hook_name="$1"
|
|
||||||
hook_exit="$2"
|
|
||||||
hook_file="$T_DIR_HOOKS/$hook_name"
|
|
||||||
{
|
|
||||||
echo "#!/bin/sh"
|
|
||||||
echo "echo ran $hook_name"
|
|
||||||
echo "env"
|
|
||||||
echo "exit $hook_exit"
|
|
||||||
} > "$hook_file"
|
|
||||||
chmod a+x "$hook_file"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (no hook)" {
|
|
||||||
echo "
|
|
||||||
When no hook is present
|
|
||||||
do no not run the hook
|
|
||||||
run command
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ $version_regex ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (successful pre hook)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run hook
|
|
||||||
run command
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "pre_version" "0"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ ran\ pre_version ]]
|
|
||||||
[[ "$output" =~ $version_regex ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (unsuccessful pre hook)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run hook
|
|
||||||
report hook failure
|
|
||||||
do no not run command
|
|
||||||
Exit with 13
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "pre_version" "13"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 13 ]
|
|
||||||
[[ "$output" =~ ran\ pre_version ]]
|
|
||||||
[[ "$output" =~ pre_version\ was\ not\ successful ]]
|
|
||||||
[[ ! "$output" =~ $version_regex ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (successful post hook)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run command
|
|
||||||
run hook
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "post_version" "0"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ $version_regex ]]
|
|
||||||
[[ "$output" =~ ran\ post_version ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (unsuccessful post hook)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run command
|
|
||||||
run hook
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "post_version" "13"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ $version_regex ]]
|
|
||||||
[[ "$output" =~ ran\ post_version ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (successful pre hook + post hook)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run hook
|
|
||||||
run command
|
|
||||||
run hook
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "pre_version" "0"
|
|
||||||
create_hook "post_version" "0"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ ran\ pre_version ]]
|
|
||||||
[[ "$output" =~ $version_regex ]]
|
|
||||||
[[ "$output" =~ ran\ post_version ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (unsuccessful pre hook + post hook)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run hook
|
|
||||||
report hook failure
|
|
||||||
do no not run command
|
|
||||||
do no not run post hook
|
|
||||||
Exit with 13
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "pre_version" "13"
|
|
||||||
create_hook "post_version" "0"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version
|
|
||||||
|
|
||||||
[ $status -eq 13 ]
|
|
||||||
[[ "$output" =~ ran\ pre_version ]]
|
|
||||||
[[ "$output" =~ pre_version\ was\ not\ successful ]]
|
|
||||||
[[ ! "$output" =~ $version_regex ]]
|
|
||||||
[[ ! "$output" =~ ran\ post_version ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Hooks (environment variables)" {
|
|
||||||
echo "
|
|
||||||
When hook is present
|
|
||||||
run command
|
|
||||||
run hook
|
|
||||||
hook should have access to environment variables
|
|
||||||
Exit with 0
|
|
||||||
"
|
|
||||||
|
|
||||||
create_hook "post_version" "0"
|
|
||||||
|
|
||||||
#; run yadm with no command
|
|
||||||
run "${T_YADM_Y[@]}" version extra_args
|
|
||||||
|
|
||||||
[ $status -eq 0 ]
|
|
||||||
[[ "$output" =~ $version_regex ]]
|
|
||||||
[[ "$output" =~ ran\ post_version ]]
|
|
||||||
[[ "$output" =~ YADM_HOOK_COMMAND=version ]]
|
|
||||||
[[ "$output" =~ YADM_HOOK_EXIT=0 ]]
|
|
||||||
[[ "$output" =~ YADM_HOOK_FULL_COMMAND=version\ extra_args ]]
|
|
||||||
[[ "$output" =~ YADM_HOOK_REPO=${T_DIR_REPO} ]]
|
|
||||||
[[ "$output" =~ YADM_HOOK_WORK=${T_DIR_WORK} ]]
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
load common
|
|
||||||
load_fixtures
|
|
||||||
status=;output=; #; populated by bats run()
|
|
||||||
|
|
||||||
IN_REPO=(.bash_profile .vimrc)
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
destroy_tmp
|
|
||||||
build_repo "${IN_REPO[@]}"
|
|
||||||
rm -rf "$T_DIR_WORK"
|
|
||||||
mkdir -p "$T_DIR_WORK"
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Private dirs (private dirs missing)" {
|
|
||||||
echo "
|
|
||||||
When a git command is run
|
|
||||||
And private directories are missing
|
|
||||||
Create private directories prior to command
|
|
||||||
"
|
|
||||||
|
|
||||||
#; confirm directories are missing at start
|
|
||||||
[ ! -e "$T_DIR_WORK/.gnupg" ]
|
|
||||||
[ ! -e "$T_DIR_WORK/.ssh" ]
|
|
||||||
|
|
||||||
#; run status
|
|
||||||
export DEBUG=yes
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ On\ branch\ master ]]
|
|
||||||
|
|
||||||
#; confirm private directories are created
|
|
||||||
[ -d "$T_DIR_WORK/.gnupg" ]
|
|
||||||
test_perms "$T_DIR_WORK/.gnupg" "drwx------"
|
|
||||||
[ -d "$T_DIR_WORK/.ssh" ]
|
|
||||||
test_perms "$T_DIR_WORK/.ssh" "drwx------"
|
|
||||||
|
|
||||||
#; confirm directories are created before command is run
|
|
||||||
[[ "$output" =~ Creating.+/.gnupg/.+Creating.+/.ssh/.+Running\ git\ command\ git\ status ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Private dirs (private dirs missing / yadm.auto-private-dirs=false)" {
|
|
||||||
echo "
|
|
||||||
When a git command is run
|
|
||||||
And private directories are missing
|
|
||||||
But auto-private-dirs is false
|
|
||||||
Do not create private dirs
|
|
||||||
"
|
|
||||||
|
|
||||||
#; confirm directories are missing at start
|
|
||||||
[ ! -e "$T_DIR_WORK/.gnupg" ]
|
|
||||||
[ ! -e "$T_DIR_WORK/.ssh" ]
|
|
||||||
|
|
||||||
#; set configuration
|
|
||||||
run "${T_YADM_Y[@]}" config --bool "yadm.auto-private-dirs" "false"
|
|
||||||
|
|
||||||
#; run status
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ On\ branch\ master ]]
|
|
||||||
|
|
||||||
#; confirm private directories are not created
|
|
||||||
[ ! -e "$T_DIR_WORK/.gnupg" ]
|
|
||||||
[ ! -e "$T_DIR_WORK/.ssh" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Private dirs (private dirs exist / yadm.auto-perms=false)" {
|
|
||||||
echo "
|
|
||||||
When a git command is run
|
|
||||||
And private directories exist
|
|
||||||
And yadm is configured not to auto update perms
|
|
||||||
Do not alter directories
|
|
||||||
"
|
|
||||||
|
|
||||||
#shellcheck disable=SC2174
|
|
||||||
mkdir -m 0777 -p "$T_DIR_WORK/.gnupg" "$T_DIR_WORK/.ssh"
|
|
||||||
|
|
||||||
#; confirm directories are preset and open
|
|
||||||
[ -d "$T_DIR_WORK/.gnupg" ]
|
|
||||||
test_perms "$T_DIR_WORK/.gnupg" "drwxrwxrwx"
|
|
||||||
[ -d "$T_DIR_WORK/.ssh" ]
|
|
||||||
test_perms "$T_DIR_WORK/.ssh" "drwxrwxrwx"
|
|
||||||
|
|
||||||
#; set configuration
|
|
||||||
run "${T_YADM_Y[@]}" config --bool "yadm.auto-perms" "false"
|
|
||||||
|
|
||||||
#; run status
|
|
||||||
run "${T_YADM_Y[@]}" status
|
|
||||||
|
|
||||||
#; validate status and output
|
|
||||||
[ "$status" -eq 0 ]
|
|
||||||
[[ "$output" =~ On\ branch\ master ]]
|
|
||||||
|
|
||||||
#; confirm directories are still preset and open
|
|
||||||
[ -d "$T_DIR_WORK/.gnupg" ]
|
|
||||||
test_perms "$T_DIR_WORK/.gnupg" "drwxrwxrwx"
|
|
||||||
[ -d "$T_DIR_WORK/.ssh" ]
|
|
||||||
test_perms "$T_DIR_WORK/.ssh" "drwxrwxrwx"
|
|
||||||
}
|
|
384
test/common.bash
384
test/common.bash
|
@ -1,384 +0,0 @@
|
||||||
|
|
||||||
#; common fixtures
|
|
||||||
function load_fixtures() {
|
|
||||||
export DEFAULT_YADM_DIR="$HOME/.yadm"
|
|
||||||
export DEFAULT_REPO="repo.git"
|
|
||||||
export DEFAULT_CONFIG="config"
|
|
||||||
export DEFAULT_ENCRYPT="encrypt"
|
|
||||||
export DEFAULT_ARCHIVE="files.gpg"
|
|
||||||
export DEFAULT_BOOTSTRAP="bootstrap"
|
|
||||||
|
|
||||||
export T_YADM="$PWD/yadm"
|
|
||||||
export T_TMP="$BATS_TMPDIR/ytmp"
|
|
||||||
export T_DIR_YADM="$T_TMP/.yadm"
|
|
||||||
export T_DIR_WORK="$T_TMP/yadm-work"
|
|
||||||
export T_DIR_REPO="$T_DIR_YADM/repo.git"
|
|
||||||
export T_DIR_HOOKS="$T_DIR_YADM/hooks"
|
|
||||||
export T_YADM_CONFIG="$T_DIR_YADM/config"
|
|
||||||
export T_YADM_ENCRYPT="$T_DIR_YADM/encrypt"
|
|
||||||
export T_YADM_ARCHIVE="$T_DIR_YADM/files.gpg"
|
|
||||||
export T_YADM_BOOTSTRAP="$T_DIR_YADM/bootstrap"
|
|
||||||
|
|
||||||
export T_YADM_Y
|
|
||||||
T_YADM_Y=( "$T_YADM" -Y "$T_DIR_YADM" )
|
|
||||||
|
|
||||||
export T_SYS
|
|
||||||
T_SYS=$(uname -s)
|
|
||||||
export T_HOST
|
|
||||||
T_HOST=$(hostname -s)
|
|
||||||
export T_USER
|
|
||||||
T_USER=$(id -u -n)
|
|
||||||
export T_DISTRO
|
|
||||||
T_DISTRO=$(lsb_release -si 2>/dev/null || true)
|
|
||||||
}
|
|
||||||
|
|
||||||
function configure_git() {
|
|
||||||
(git config user.name || git config --global user.name 'test') >/dev/null
|
|
||||||
(git config user.email || git config --global user.email 'test@test.test') > /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
function make_parents() {
|
|
||||||
local parent_dir
|
|
||||||
parent_dir=$(dirname "$@")
|
|
||||||
mkdir -p "$parent_dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_perms() {
|
|
||||||
local test_path="$1"
|
|
||||||
local regex="$2"
|
|
||||||
local ls
|
|
||||||
ls=$(ls -ld "$test_path")
|
|
||||||
local perms="${ls:0:10}"
|
|
||||||
if [[ ! $perms =~ $regex ]]; then
|
|
||||||
echo "ERROR: Found permissions $perms for $test_path"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_repo_attribute() {
|
|
||||||
local repo_dir="$1"
|
|
||||||
local attribute="$2"
|
|
||||||
local expected="$3"
|
|
||||||
local actual
|
|
||||||
actual=$(GIT_DIR="$repo_dir" git config --local "$attribute")
|
|
||||||
if [ "$actual" != "$expected" ]; then
|
|
||||||
echo "ERROR: repo attribute $attribute set to $actual"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
#; create worktree at path
|
|
||||||
function create_worktree() {
|
|
||||||
local DIR_WORKTREE="$1"
|
|
||||||
if [ -z "$DIR_WORKTREE" ]; then
|
|
||||||
echo "ERROR: create_worktree() called without a path"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! "$DIR_WORKTREE" =~ ^$T_TMP ]]; then
|
|
||||||
echo "ERROR: create_worktree() called with a path outside of $T_TMP"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; remove any existing data
|
|
||||||
rm -rf "$DIR_WORKTREE"
|
|
||||||
|
|
||||||
#; create some standard files
|
|
||||||
if [ ! -z "$TEST_TREE_WITH_ALT" ] ; then
|
|
||||||
for f in \
|
|
||||||
"alt-none##S" \
|
|
||||||
"alt-none##S.H" \
|
|
||||||
"alt-none##S.H.U" \
|
|
||||||
"alt-base##" \
|
|
||||||
"alt-base##S" \
|
|
||||||
"alt-base##S.H" \
|
|
||||||
"alt-base##S.H.U" \
|
|
||||||
"alt-system##" \
|
|
||||||
"alt-system##S" \
|
|
||||||
"alt-system##S.H" \
|
|
||||||
"alt-system##S.H.U" \
|
|
||||||
"alt-system##$T_SYS" \
|
|
||||||
"alt-system##AAA" \
|
|
||||||
"alt-system##ZZZ" \
|
|
||||||
"alt-system##aaa" \
|
|
||||||
"alt-system##zzz" \
|
|
||||||
"alt-host##" \
|
|
||||||
"alt-host##S" \
|
|
||||||
"alt-host##S.H" \
|
|
||||||
"alt-host##S.H.U" \
|
|
||||||
"alt-host##$T_SYS.$T_HOST" \
|
|
||||||
"alt-host##${T_SYS}_${T_HOST}" \
|
|
||||||
"alt-user##" \
|
|
||||||
"alt-user##S" \
|
|
||||||
"alt-user##S.H" \
|
|
||||||
"alt-user##S.H.U" \
|
|
||||||
"alt-user##$T_SYS.$T_HOST.$T_USER" \
|
|
||||||
"alt-user##${T_SYS}_${T_HOST}_${T_USER}" \
|
|
||||||
"alt-override-system##" \
|
|
||||||
"alt-override-system##$T_SYS" \
|
|
||||||
"alt-override-system##custom_system" \
|
|
||||||
"alt-override-host##" \
|
|
||||||
"alt-override-host##$T_SYS.$T_HOST" \
|
|
||||||
"alt-override-host##$T_SYS.custom_host" \
|
|
||||||
"alt-override-user##" \
|
|
||||||
"alt-override-user##S.H.U" \
|
|
||||||
"alt-override-user##$T_SYS.$T_HOST.custom_user" \
|
|
||||||
"dir one/alt-none##S/file1" \
|
|
||||||
"dir one/alt-none##S/file2" \
|
|
||||||
"dir one/alt-none##S.H/file1" \
|
|
||||||
"dir one/alt-none##S.H/file2" \
|
|
||||||
"dir one/alt-none##S.H.U/file1" \
|
|
||||||
"dir one/alt-none##S.H.U/file2" \
|
|
||||||
"dir one/alt-base##/file1" \
|
|
||||||
"dir one/alt-base##/file2" \
|
|
||||||
"dir one/alt-base##S/file1" \
|
|
||||||
"dir one/alt-base##S/file2" \
|
|
||||||
"dir one/alt-base##S.H/file1" \
|
|
||||||
"dir one/alt-base##S.H/file2" \
|
|
||||||
"dir one/alt-base##S.H.U/file1" \
|
|
||||||
"dir one/alt-base##S.H.U/file2" \
|
|
||||||
"dir one/alt-system##/file1" \
|
|
||||||
"dir one/alt-system##/file2" \
|
|
||||||
"dir one/alt-system##S/file1" \
|
|
||||||
"dir one/alt-system##S/file2" \
|
|
||||||
"dir one/alt-system##S.H/file1" \
|
|
||||||
"dir one/alt-system##S.H/file2" \
|
|
||||||
"dir one/alt-system##S.H.U/file1" \
|
|
||||||
"dir one/alt-system##S.H.U/file2" \
|
|
||||||
"dir one/alt-system##$T_SYS/file1" \
|
|
||||||
"dir one/alt-system##$T_SYS/file2" \
|
|
||||||
"dir one/alt-system##AAA/file1" \
|
|
||||||
"dir one/alt-system##AAA/file2" \
|
|
||||||
"dir one/alt-system##ZZZ/file1" \
|
|
||||||
"dir one/alt-system##ZZZ/file2" \
|
|
||||||
"dir one/alt-system##aaa/file1" \
|
|
||||||
"dir one/alt-system##aaa/file2" \
|
|
||||||
"dir one/alt-system##zzz/file1" \
|
|
||||||
"dir one/alt-system##zzz/file2" \
|
|
||||||
"dir one/alt-host##/file1" \
|
|
||||||
"dir one/alt-host##/file2" \
|
|
||||||
"dir one/alt-host##S/file1" \
|
|
||||||
"dir one/alt-host##S/file2" \
|
|
||||||
"dir one/alt-host##S.H/file1" \
|
|
||||||
"dir one/alt-host##S.H/file2" \
|
|
||||||
"dir one/alt-host##S.H.U/file1" \
|
|
||||||
"dir one/alt-host##S.H.U/file2" \
|
|
||||||
"dir one/alt-host##$T_SYS.$T_HOST/file1" \
|
|
||||||
"dir one/alt-host##$T_SYS.$T_HOST/file2" \
|
|
||||||
"dir one/alt-host##${T_SYS}_${T_HOST}/file1" \
|
|
||||||
"dir one/alt-host##${T_SYS}_${T_HOST}/file2" \
|
|
||||||
"dir one/alt-user##/file1" \
|
|
||||||
"dir one/alt-user##/file2" \
|
|
||||||
"dir one/alt-user##S/file1" \
|
|
||||||
"dir one/alt-user##S/file2" \
|
|
||||||
"dir one/alt-user##S.H/file1" \
|
|
||||||
"dir one/alt-user##S.H/file2" \
|
|
||||||
"dir one/alt-user##S.H.U/file1" \
|
|
||||||
"dir one/alt-user##S.H.U/file2" \
|
|
||||||
"dir one/alt-user##$T_SYS.$T_HOST.$T_USER/file1" \
|
|
||||||
"dir one/alt-user##$T_SYS.$T_HOST.$T_USER/file2" \
|
|
||||||
"dir one/alt-user##${T_SYS}_${T_HOST}_${T_USER}/file1" \
|
|
||||||
"dir one/alt-user##${T_SYS}_${T_HOST}_${T_USER}/file2" \
|
|
||||||
"dir one/alt-override-system##/file1" \
|
|
||||||
"dir one/alt-override-system##/file2" \
|
|
||||||
"dir one/alt-override-system##$T_SYS/file1" \
|
|
||||||
"dir one/alt-override-system##$T_SYS/file2" \
|
|
||||||
"dir one/alt-override-system##custom_system/file1" \
|
|
||||||
"dir one/alt-override-system##custom_system/file2" \
|
|
||||||
"dir one/alt-override-host##/file1" \
|
|
||||||
"dir one/alt-override-host##/file2" \
|
|
||||||
"dir one/alt-override-host##$T_SYS.$T_HOST/file1" \
|
|
||||||
"dir one/alt-override-host##$T_SYS.$T_HOST/file2" \
|
|
||||||
"dir one/alt-override-host##$T_SYS.custom_host/file1" \
|
|
||||||
"dir one/alt-override-host##$T_SYS.custom_host/file2" \
|
|
||||||
"dir one/alt-override-user##/file1" \
|
|
||||||
"dir one/alt-override-user##/file2" \
|
|
||||||
"dir one/alt-override-user##S.H.U/file1" \
|
|
||||||
"dir one/alt-override-user##S.H.U/file2" \
|
|
||||||
"dir one/alt-override-user##$T_SYS.$T_HOST.custom_user/file1" \
|
|
||||||
"dir one/alt-override-user##$T_SYS.$T_HOST.custom_user/file2" \
|
|
||||||
"dir2/file2" \
|
|
||||||
;
|
|
||||||
do
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
echo "{{ YADM_CLASS }}-{{ YADM_OS }}-{{ YADM_HOSTNAME }}-{{ YADM_USER }}-{{ YADM_DISTRO }}" > "$DIR_WORKTREE/alt-jinja##yadm.j2"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; for some cygwin tests
|
|
||||||
if [ ! -z "$TEST_TREE_WITH_CYGWIN" ] ; then
|
|
||||||
for f in \
|
|
||||||
"alt-test##" \
|
|
||||||
"alt-test##$T_SYS" \
|
|
||||||
"alt-test##$SIMULATED_CYGWIN" \
|
|
||||||
;
|
|
||||||
do
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -z "$TEST_TREE_WITH_WILD" ] ; then
|
|
||||||
#; wildcard test data - yes this is a big mess :(
|
|
||||||
#; none
|
|
||||||
for f in "wild-none##"; do
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
#; system
|
|
||||||
for WILD_S in 'local' 'wild' 'other'; do
|
|
||||||
local s_base="wild-system-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
local f="${s_base}##${WILD_S}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
#; system.host
|
|
||||||
for WILD_S in 'local' 'wild' 'other'; do
|
|
||||||
local s_base="wild-host-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild' 'other'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
local f="${h_base}##${WILD_S}.${WILD_H}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
#; system.host.user
|
|
||||||
for WILD_S in 'local' 'wild' 'other'; do
|
|
||||||
local s_base="wild-user-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild' 'other'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
for WILD_U in 'local' 'wild' 'other'; do
|
|
||||||
local u_base="${h_base}-$WILD_U"
|
|
||||||
case $WILD_U in local) WILD_U="$T_USER";; wild) WILD_U="%";; esac
|
|
||||||
local f="${u_base}##${WILD_S}.${WILD_H}.${WILD_U}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
#; class
|
|
||||||
for WILD_C in 'local' 'wild' 'other'; do
|
|
||||||
local c_base="wild-class-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
local f="${c_base}##${WILD_C}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
#; class.system
|
|
||||||
for WILD_C in 'local' 'wild' 'other'; do
|
|
||||||
local c_base="wild-class-system-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
for WILD_S in 'local' 'wild' 'other'; do
|
|
||||||
local s_base="${c_base}-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
local f="${s_base}##${WILD_C}.${WILD_S}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
#; class.system.host
|
|
||||||
for WILD_C in 'local' 'wild' 'other'; do
|
|
||||||
local c_base="wild-class-system-host-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
for WILD_S in 'local' 'wild' 'other'; do
|
|
||||||
local s_base="${c_base}-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild' 'other'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
local f="${h_base}##${WILD_C}.${WILD_S}.${WILD_H}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
#; class.system.host.user
|
|
||||||
for WILD_C in 'local' 'wild' 'other'; do
|
|
||||||
local c_base="wild-class-system-host-user-$WILD_C"
|
|
||||||
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
|
|
||||||
for WILD_S in 'local' 'wild' 'other'; do
|
|
||||||
local s_base="${c_base}-$WILD_S"
|
|
||||||
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
|
|
||||||
for WILD_H in 'local' 'wild' 'other'; do
|
|
||||||
local h_base="${s_base}-$WILD_H"
|
|
||||||
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
|
|
||||||
for WILD_U in 'local' 'wild' 'other'; do
|
|
||||||
local u_base="${h_base}-$WILD_U"
|
|
||||||
case $WILD_U in local) WILD_U="$T_USER";; wild) WILD_U="%";; esac
|
|
||||||
local f="${u_base}##${WILD_C}.${WILD_S}.${WILD_H}.${WILD_U}"
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
for f in \
|
|
||||||
.bash_profile \
|
|
||||||
.gnupg/gpg.conf \
|
|
||||||
.gnupg/pubring.gpg \
|
|
||||||
.gnupg/secring.gpg \
|
|
||||||
.hammerspoon/init.lua \
|
|
||||||
.ssh/config \
|
|
||||||
.ssh/secret.key \
|
|
||||||
.ssh/secret.pub \
|
|
||||||
.tmux.conf \
|
|
||||||
.vimrc \
|
|
||||||
"space test/file one" \
|
|
||||||
"space test/file two" \
|
|
||||||
;
|
|
||||||
do
|
|
||||||
make_parents "$DIR_WORKTREE/$f"
|
|
||||||
echo "$f" > "$DIR_WORKTREE/$f"
|
|
||||||
done
|
|
||||||
|
|
||||||
#; change all perms (so permission updates can be observed)
|
|
||||||
find "$DIR_WORKTREE" -exec chmod 0777 '{}' ';'
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#; create a repo in T_DIR_REPO
|
|
||||||
function build_repo() {
|
|
||||||
local files_to_add=( "$@" )
|
|
||||||
|
|
||||||
#; create a worktree
|
|
||||||
create_worktree "$T_DIR_WORK"
|
|
||||||
|
|
||||||
#; remove the repo if it exists
|
|
||||||
if [ -e "$T_DIR_REPO" ]; then
|
|
||||||
rm -rf "$T_DIR_REPO"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#; create the repo
|
|
||||||
git init --shared=0600 --bare "$T_DIR_REPO" >/dev/null 2>&1
|
|
||||||
|
|
||||||
#; standard repo config
|
|
||||||
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 status.showUntrackedFiles no
|
|
||||||
GIT_DIR="$T_DIR_REPO" git config yadm.managed 'true'
|
|
||||||
|
|
||||||
if [ ${#files_to_add[@]} -ne 0 ]; then
|
|
||||||
for f in "${files_to_add[@]}"; do
|
|
||||||
GIT_DIR="$T_DIR_REPO" git add "$T_DIR_WORK/$f" >/dev/null
|
|
||||||
done
|
|
||||||
GIT_DIR="$T_DIR_REPO" git commit -m 'Create repo template' >/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#; remove all tmp files
|
|
||||||
function destroy_tmp() {
|
|
||||||
load_fixtures
|
|
||||||
rm -rf "$T_TMP"
|
|
||||||
}
|
|
||||||
|
|
||||||
configure_git
|
|
Loading…
Reference in a new issue