boring_backup/tests/source_script.bats

82 lines
2.4 KiB
Plaintext
Raw Permalink Normal View History

2022-05-15 07:20:37 +03:00
#!/usr/bin/env bats
2022-05-14 03:36:13 +03:00
2022-05-14 17:49:46 +03:00
# source_script() from lib/source.sh tests.
2022-05-14 03:36:13 +03:00
# 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" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/bad_syntax.sh
2022-05-17 01:28:15 +03:00
assert_output --partial 'Error: script.sh: Please check your syntax'
2022-05-14 03:36:13 +03:00
}
@test "Empty script" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/empty_script.sh
2022-05-17 01:28:15 +03:00
assert_output --partial 'Error: script.sh: sources array is not set'
2022-05-14 03:36:13 +03:00
}
@test "Empty sources array" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/empty_sources.sh
2022-05-17 01:28:15 +03:00
assert_output --partial 'Error: script.sh: sources array is not set'
2022-05-14 03:36:13 +03:00
}
@test "Empty targets array" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/empty_targets.sh
2022-05-17 01:28:15 +03:00
assert_output --partial 'Error: script.sh: targets array is not set'
2022-05-14 03:36:13 +03:00
}
@test "No targets with 'file' URI scheme" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/no_file_target.sh
2022-05-17 01:28:15 +03:00
assert_output --partial "Error: script.sh: 'file' scheme is not set in targets. You must provide one or more targets with 'file' scheme."
2022-05-14 03:36:13 +03:00
}
@test "Unsuported source scheme" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/unsupported_source_scheme.sh
2022-05-17 01:28:15 +03:00
assert_output --partial 'Error: script.sh: Unsupported URI scheme: mongo'
2022-05-14 03:36:13 +03:00
}
@test "Unsuported target scheme" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-08-21 04:52:56 +03:00
backup_script=script.sh
2022-05-17 00:04:03 +03:00
run source_script $DIR/files/unsupported_target_scheme.sh
2022-05-17 01:28:15 +03:00
assert_output --partial 'Error: script.sh: Unsupported URI scheme: scp'
2022-05-14 03:36:13 +03:00
}
2022-05-14 20:10:49 +03:00
@test "Set __main_target" {
2022-05-14 17:49:46 +03:00
. source.sh
. uri.sh # for parse_uri()
2022-05-17 00:04:03 +03:00
source_script $DIR/files/basic.sh
2022-05-15 11:40:57 +03:00
[ "$__main_target" == 'file:/etc/lvm/backup' ]
[ "$__main_target_path" == '/etc/lvm/backup' ]
}
2022-05-14 20:10:49 +03:00
@test "Set __main_target from multiple 'file' targets" {
2022-05-14 17:49:46 +03:00
. source.sh
. uri.sh # for parse_uri()
2022-05-17 00:04:03 +03:00
source_script $DIR/files/multiple_file_targets.sh
2022-05-15 11:40:57 +03:00
[ "$__main_target" == 'file:///etc/lvm/backup' ]
[ "$__main_target_path" == '/etc/lvm/backup' ]
}