boring_backup/tests/source_script.bats
2022-08-21 04:52:56 +03:00

82 lines
2.4 KiB
Bash

#!/usr/bin/env bats
# source_script() from lib/source.sh tests.
# See: https://bats-core.readthedocs.io/en/latest/index.html
setup() {
# Bats setup
load 'helpers/bats-support/load'
load 'helpers/bats-assert/load'
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/../src/lib:$PATH"
}
# ------------------------------ #
# Do tests! #
# ------------------------------ #
@test "Bad script syntax" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/bad_syntax.sh
assert_output --partial 'Error: script.sh: Please check your syntax'
}
@test "Empty script" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/empty_script.sh
assert_output --partial 'Error: script.sh: sources array is not set'
}
@test "Empty sources array" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/empty_sources.sh
assert_output --partial 'Error: script.sh: sources array is not set'
}
@test "Empty targets array" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/empty_targets.sh
assert_output --partial 'Error: script.sh: targets array is not set'
}
@test "No targets with 'file' URI scheme" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/no_file_target.sh
assert_output --partial "Error: script.sh: 'file' scheme is not set in targets. You must provide one or more targets with 'file' scheme."
}
@test "Unsuported source scheme" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/unsupported_source_scheme.sh
assert_output --partial 'Error: script.sh: Unsupported URI scheme: mongo'
}
@test "Unsuported target scheme" {
. source.sh
backup_script=script.sh
run source_script $DIR/files/unsupported_target_scheme.sh
assert_output --partial 'Error: script.sh: Unsupported URI scheme: scp'
}
@test "Set __main_target" {
. source.sh
. uri.sh # for parse_uri()
source_script $DIR/files/basic.sh
[ "$__main_target" == 'file:/etc/lvm/backup' ]
[ "$__main_target_path" == '/etc/lvm/backup' ]
}
@test "Set __main_target from multiple 'file' targets" {
. source.sh
. uri.sh # for parse_uri()
source_script $DIR/files/multiple_file_targets.sh
[ "$__main_target" == 'file:///etc/lvm/backup' ]
[ "$__main_target_path" == '/etc/lvm/backup' ]
}