local full_backup_path="$3"
local pathes=()
mapfile -t pathes < <(echo "$config" \
- | jq --raw-output ".machines.$machine.pathes[]")
+ | jq --raw-output ".machines.$machine.pathes[]" \
+ 2> /dev/null)
+ [ "${#pathes[@]}" -ne "0" ] \
+ || errlog "missing pathes for machine $machine" \
+ || return $?
[ -n "$NOCOLOR" ] && YELLOW= && LIGHTPURPLE= && RESET=
local path=
assert_line --index 5 "✅ SUCCESS: backup"
}
-@test "last backup dir path info" {
+@test "success last backup dir path info" {
create_backup_dir() {
:
}
assert_line --index 6 "✅ SUCCESS: backup"
}
-@test "new backup folder info" {
+@test "success new backup folder info" {
create_backup_dir() {
:
}
assert_line --index 5 "✅ SUCCESS: backup"
}
-@test "new backup folder with number 02 info" {
+@test "success new backup folder with number 02 info" {
mkdir --parents "build/2000-01-01_01_backup"
create_backup_dir() {
:
rmdir "build/2000-01-01_01_backup"
}
-@test "create backup folder" {
+@test "success create backup folder" {
backup_machines() {
:
}
[ -d "build/2000-01-01_01_backup" ]
}
-@test "backup machines" {
+@test "success backup machines" {
machine_backup_pathes() {
:
}
[ -d "build/2000-01-01_01_backup/testpc2" ]
}
-@test "backup remote pathes" {
+@test "success backup machine pathes" {
run main
assert_success
assert_line --index 15 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc2${RESET}; path ${YELLOW}/home/other${RESET}"
assert_line --index 16 "################################################################################"
assert_line --index 17 "✅ SUCCESS: backup"
+}
+
+@test "failure backup machine pathes is null" {
+ yq() {
+ echo '{
+ "backup_path": "build",
+ "backup_name": "backup",
+ "backup_count": 15,
+ "machines": {
+ "testpc1": null
+ }
+ }'
+ }
+
+ run main
+
+ assert_failure
+ assert_line --index 0 "⭐ START: backup"
+ assert_line --index 1 "ℹ️ INFO: backup path build"
+ assert_line --index 2 "ℹ️ INFO: backup name backup"
+ assert_line --index 3 "ℹ️ INFO: backup count 15"
+ assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
+ assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
+ assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "❌ ERROR: missing pathes for machine testpc1"
}
\ No newline at end of file