feat: Add script.sh with tests
This commit is contained in:
2
tests/files/bad_syntax.plan
Normal file
2
tests/files/bad_syntax.plan
Normal file
@ -0,0 +1,2 @@
|
||||
sources= ('file:/home/user')
|
||||
targets=('file:/var/backup')
|
0
tests/files/empty_script.plan
Normal file
0
tests/files/empty_script.plan
Normal file
2
tests/files/empty_sources.plan
Normal file
2
tests/files/empty_sources.plan
Normal file
@ -0,0 +1,2 @@
|
||||
sources=()
|
||||
targets=('file:/var/backup')
|
2
tests/files/empty_targets.plan
Normal file
2
tests/files/empty_targets.plan
Normal file
@ -0,0 +1,2 @@
|
||||
sources=('file:/home/user')
|
||||
targets=()
|
2
tests/files/no_file_target.plan
Normal file
2
tests/files/no_file_target.plan
Normal file
@ -0,0 +1,2 @@
|
||||
sources=(file:///)
|
||||
targets=(ftp://user:pass@host/path)
|
2
tests/files/unsupported_source_scheme.plan
Normal file
2
tests/files/unsupported_source_scheme.plan
Normal file
@ -0,0 +1,2 @@
|
||||
sources=('mongo:/user:password@localhost/database')
|
||||
targets=('file:/var/backup')
|
2
tests/files/unsupported_target_scheme.plan
Normal file
2
tests/files/unsupported_target_scheme.plan
Normal file
@ -0,0 +1,2 @@
|
||||
sources=('file:/home/user')
|
||||
targets=(scp://user:pass@host/path)
|
58
tests/source_script.bats
Normal file
58
tests/source_script.bats
Normal file
@ -0,0 +1,58 @@
|
||||
#! /usr/bin/env bats
|
||||
|
||||
# source_script() from lib/script.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" {
|
||||
. script.sh
|
||||
run source_script $DIR/files/bad_syntax.plan
|
||||
assert_output --partial 'Error: Please check your syntax'
|
||||
}
|
||||
|
||||
@test "Empty script" {
|
||||
. script.sh
|
||||
run source_script $DIR/files/empty_script.plan
|
||||
assert_output --partial 'Error: sources array is not set'
|
||||
}
|
||||
|
||||
@test "Empty sources array" {
|
||||
. script.sh
|
||||
run source_script $DIR/files/empty_sources.plan
|
||||
assert_output --partial 'Error: sources array is not set'
|
||||
}
|
||||
|
||||
@test "Empty targets array" {
|
||||
. script.sh
|
||||
run source_script $DIR/files/empty_targets.plan
|
||||
assert_output --partial 'Error: targets array is not set'
|
||||
}
|
||||
|
||||
@test "No targets with file URI scheme" {
|
||||
. script.sh
|
||||
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" {
|
||||
. script.sh
|
||||
run source_script $DIR/files/unsupported_source_scheme.plan
|
||||
assert_output --partial 'Error: Unsupported URI scheme: mongo'
|
||||
}
|
||||
|
||||
@test "Unsuported target scheme" {
|
||||
. script.sh
|
||||
run source_script $DIR/files/unsupported_target_scheme.plan
|
||||
assert_output --partial 'Error: Unsupported URI scheme: scp'
|
||||
}
|
Reference in New Issue
Block a user