boring_backup/tests/source_script.bats

71 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-05-14 03:36:13 +03:00
#! /usr/bin/env bats
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-05-14 03:36:13 +03:00
run source_script $DIR/files/bad_syntax.plan
assert_output --partial 'Error: Please check your syntax'
}
@test "Empty script" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-05-14 03:36:13 +03:00
run source_script $DIR/files/empty_script.plan
assert_output --partial 'Error: sources array is not set'
}
@test "Empty sources array" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-05-14 03:36:13 +03:00
run source_script $DIR/files/empty_sources.plan
assert_output --partial 'Error: sources array is not set'
}
@test "Empty targets array" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-05-14 03:36:13 +03:00
run source_script $DIR/files/empty_targets.plan
assert_output --partial 'Error: targets array is not set'
}
@test "No targets with 'file' URI scheme" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-05-14 03:36:13 +03:00
run source_script $DIR/files/no_file_target.plan
assert_output --partial "Error: 'file' scheme is not set in targets. You must provide one or more targets with 'file' scheme."
}
@test "Unsuported source scheme" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-05-14 03:36:13 +03:00
run source_script $DIR/files/unsupported_source_scheme.plan
assert_output --partial 'Error: Unsupported URI scheme: mongo'
}
@test "Unsuported target scheme" {
2022-05-14 17:49:46 +03:00
. source.sh
2022-05-14 03:36:13 +03:00
run source_script $DIR/files/unsupported_target_scheme.plan
assert_output --partial 'Error: Unsupported URI scheme: scp'
}
2022-05-14 20:10:49 +03:00
@test "Set __main_target" {
2022-05-14 17:49:46 +03:00
. source.sh
source_script $DIR/files/basic.plan
2022-05-14 20:10:49 +03:00
[ "$__main_target" == 'file:/var/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
source_script $DIR/files/multiple_file_targets.plan
2022-05-14 20:10:49 +03:00
[ "$__main_target" == 'file:///home/backups' ]
}