Refactor path tests
Including new path tests for planned features
This commit is contained in:
parent
340f88bd52
commit
27d0e7baa2
3 changed files with 180 additions and 105 deletions
|
@ -1,70 +0,0 @@
|
|||
load common
|
||||
load_fixtures
|
||||
|
||||
@test "configure_paths() (standard YADM_DIR)" {
|
||||
echo "
|
||||
Correct paths should be defined
|
||||
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
|
||||
GIT_DIR=$DEFAULT_YADM_DIR/$DEFAULT_REPO
|
||||
"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
#; load yadm functions
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
|
||||
#; configure the paths
|
||||
configure_paths
|
||||
|
||||
echo "CONFIGURED PATHS:"
|
||||
echo " YADM_REPO:$YADM_REPO"
|
||||
echo " YADM_CONFIG:$YADM_CONFIG"
|
||||
echo "YADM_ENCRYPT:$YADM_ENCRYPT"
|
||||
echo "YADM_ARCHIVE:$YADM_ARCHIVE"
|
||||
echo " GIT_DIR:$GIT_DIR"
|
||||
|
||||
#; test value of configured paths
|
||||
[ "$DEFAULT_YADM_DIR/$DEFAULT_REPO" = "$YADM_REPO" ]
|
||||
[ "$DEFAULT_YADM_DIR/$DEFAULT_CONFIG" = "$YADM_CONFIG" ]
|
||||
[ "$DEFAULT_YADM_DIR/$DEFAULT_ENCRYPT" = "$YADM_ENCRYPT" ]
|
||||
[ "$DEFAULT_YADM_DIR/$DEFAULT_ARCHIVE" = "$YADM_ARCHIVE" ]
|
||||
[ "$DEFAULT_YADM_DIR/$DEFAULT_REPO" = "$GIT_DIR" ]
|
||||
}
|
||||
|
||||
@test "configure_paths() (custom YADM_DIR)" {
|
||||
echo "
|
||||
Correct paths should be defined
|
||||
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
|
||||
GIT_DIR=$T_DIR_YADM/$DEFAULT_REPO
|
||||
"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
#; load yadm functions
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
|
||||
#; configure the paths
|
||||
TEST_ARGS=(-Y $T_DIR_YADM)
|
||||
process_global_args "${TEST_ARGS[@]}"
|
||||
configure_paths
|
||||
|
||||
echo "CONFIGURED PATHS:"
|
||||
echo " YADM_REPO:$YADM_REPO"
|
||||
echo " YADM_CONFIG:$YADM_CONFIG"
|
||||
echo "YADM_ENCRYPT:$YADM_ENCRYPT"
|
||||
echo "YADM_ARCHIVE:$YADM_ARCHIVE"
|
||||
echo " GIT_DIR:$GIT_DIR"
|
||||
|
||||
#; test value of configured paths
|
||||
[ "$T_DIR_YADM/$DEFAULT_REPO" = "$YADM_REPO" ]
|
||||
[ "$T_DIR_YADM/$DEFAULT_CONFIG" = "$YADM_CONFIG" ]
|
||||
[ "$T_DIR_YADM/$DEFAULT_ENCRYPT" = "$YADM_ENCRYPT" ]
|
||||
[ "$T_DIR_YADM/$DEFAULT_ARCHIVE" = "$YADM_ARCHIVE" ]
|
||||
[ "$T_DIR_YADM/$DEFAULT_REPO" = "$GIT_DIR" ]
|
||||
}
|
180
test/001_unit_paths.bats
Normal file
180
test/001_unit_paths.bats
Normal file
|
@ -0,0 +1,180 @@
|
|||
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 " 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
|
||||
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" ]
|
||||
[ "$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" ]
|
||||
[ "$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 ]]
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
load common
|
||||
load_fixtures
|
||||
|
||||
@test "Default YADM_DIR" {
|
||||
echo "
|
||||
YADM_DIR should default to \$HOME/.yadm
|
||||
"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
#; load yadm functions
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
|
||||
#; test value of YADM_DIR
|
||||
[ "$HOME/.yadm" = "$YADM_DIR" ]
|
||||
}
|
||||
|
||||
@test "Override default YADM_DIR" {
|
||||
echo "
|
||||
Override YADM_DIR using -Y $T_DIR_YADM
|
||||
YADM_DIR should become $T_DIR_YADM
|
||||
"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
#; load yadm functions
|
||||
YADM_TEST=1 source "$T_YADM"
|
||||
|
||||
#; call process_global_args() with -Y
|
||||
TEST_ARGS=(-Y $T_DIR_YADM)
|
||||
process_global_args "${TEST_ARGS[@]}"
|
||||
|
||||
#; test value of YADM_DIR
|
||||
[ "$T_DIR_YADM" = "$YADM_DIR" ]
|
||||
}
|
Loading…
Reference in a new issue