unset RSYNC_LOG_RUNS
}
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
@test "failure yq command not found" {
command() {
return 1
assert_line --index 0 "❌ ERROR: command yq not found"
}
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
@test "failure jq command not found" {
command() {
[ "$2" != "jq" ] || return 1
assert_line --index 0 "❌ ERROR: command jq not found"
}
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
@test "failure rsync command not found" {
command() {
[ "$2" != "rsync" ] || return 1
assert_line --index 0 "❌ ERROR: command rsync not found"
}
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
@test "failure ssh command not found" {
command() {
[ "$2" != "ssh" ] || return 1
assert_line --index 0 "❌ ERROR: command ssh not found"
}
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
@test "failure config.yaml not found" {
exists_config_file() {
errlog "file config.yaml not found"
assert_line --index 0 "❌ ERROR: file config.yaml not found"
}
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
@test "failure load config.yaml" {
yq() {
return 1
assert_line --index 0 "❌ ERROR: failed to load src/config-example.yaml"
}
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
@test "failure no backup path in config" {
yq() {
echo '{}'
assert_line --index 1 "❌ ERROR: src/config-example.yaml missing backup_path"
}
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
@test "failure no backup name in config" {
yq() {
echo '{"backup_path": "path"}'
assert_line --index 2 "❌ ERROR: src/config-example.yaml missing backup_name"
}
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
@test "failure no machines in config" {
yq() {
echo '{
assert_line --index 3 "❌ ERROR: src/config-example.yaml missing machines"
}
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
@test "failure date parameter missing" {
run main
assert_line --index 3 "❌ ERROR: missing date (-d)"
}
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
@test "failure number parameter missing" {
run main -d "2000-01-01"
assert_line --index 3 "❌ ERROR: missing number (-n)"
}
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
@test "failure number parameter must two digits" {
run main -d "2000-01-01" -n "1"
assert_line --index 3 "❌ ERROR: number must two digits"
}
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
@test "failure machine parameter missing" {
run main -d "2000-01-01" -n "01"
assert_line --index 3 "❌ ERROR: missing machine (-r)"
}
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
@test "failure path parameter missing" {
run main -d "2000-01-01" -n "01" -r "testpc1.example.com"
assert_line --index 3 "❌ ERROR: missing path (-p)"
}
-# bats test_tags=backup:config
+# bats test_tags=restore:config
@test "failure config missing remote user" {
yq() {
echo '{
assert_line --index 3 "❌ ERROR: missing remote user in src/config-example.yaml"
}
-# bats test_tags=backup:config
+# bats test_tags=restore:config
@test "failure config missing host" {
yq() {
echo '{
assert_line --index 3 "❌ ERROR: missing host in src/config-example.yaml"
}
-# bats test_tags=backup:config
+# bats test_tags=restore:config
@test "failure config missing remote port" {
yq() {
echo '{
assert_line --index 3 "❌ ERROR: missing port in src/config-example.yaml"
}
-# bats test_tags=backup:pathcheck
+# bats test_tags=restore:pathcheck
@test "failure no backup directory" {
run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
assert_line --index 3 "❌ ERROR: directory build/test/2000-01-01_01_backup not exists"
}
-# bats test_tags=backup:pathcheck
+# bats test_tags=restore:pathcheck
@test "failure no backup directory machine" {
mkdir --parents "build/test/2000-01-01_01_backup"
assert_line --index 1 "ℹ️ INFO: backup path build/test"
assert_line --index 2 "ℹ️ INFO: backup name backup"
assert_line --index 3 "❌ ERROR: directory build/test/2000-01-01_01_backup/testpc1.example.com not exists"
+}
+
+# bats test_tags=restore:mode
+@test "success directory mode" {
+ mkdir --parents "build/test/2000-01-01_01_backup/testpc1.example.com/testpath"
+
+ run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath/"
+
+ assert_success
+ assert_line --index 0 "⭐ START: restore"
+ assert_line --index 1 "ℹ️ INFO: backup path build/test"
+ assert_line --index 2 "ℹ️ INFO: backup name backup"
+ assert_line --index 3 "ℹ️ INFO: restore mode directory"
+ assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/testpc1.example.com/testpath/"
+ assert_line --index 5 "ℹ️ INFO: remote path backupuser@www.example.com:/testpath/"
+}
+
+# bats test_tags=restore:mode
+@test "success file mode" {
+ mkdir --parents "build/test/2000-01-01_01_backup/testpc1.example.com/testpath"
+
+ run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
+
+ assert_success
+ assert_line --index 0 "⭐ START: restore"
+ assert_line --index 1 "ℹ️ INFO: backup path build/test"
+ assert_line --index 2 "ℹ️ INFO: backup name backup"
+ assert_line --index 3 "ℹ️ INFO: restore mode file"
+ assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/testpc1.example.com/testpath"
+ assert_line --index 5 "ℹ️ INFO: remote path backupuser@www.example.com:/testpath"
+}
+
+# bats test_tags=restore:mode
+@test "success directory mode on localhost" {
+ mkdir --parents "build/test/2000-01-01_01_backup/onlylocal/testpath"
+
+ run main -d "2000-01-01" -n "01" -r "onlylocal" -p "/testpath/"
+
+ assert_success
+ assert_line --index 0 "⭐ START: restore"
+ assert_line --index 1 "ℹ️ INFO: backup path build/test"
+ assert_line --index 2 "ℹ️ INFO: backup name backup"
+ assert_line --index 3 "ℹ️ INFO: restore mode directory"
+ assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath/"
+ assert_line --index 5 "ℹ️ INFO: remote path /testpath/"
+}
+
+# bats test_tags=restore:mode
+@test "success file mode on localhost" {
+ mkdir --parents "build/test/2000-01-01_01_backup/onlylocal/testpath"
+
+ run main -d "2000-01-01" -n "01" -r "onlylocal" -p "/testpath"
+
+ assert_success
+ assert_line --index 0 "⭐ START: restore"
+ assert_line --index 1 "ℹ️ INFO: backup path build/test"
+ assert_line --index 2 "ℹ️ INFO: backup name backup"
+ assert_line --index 3 "ℹ️ INFO: restore mode file"
+ assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath"
+ assert_line --index 5 "ℹ️ INFO: remote path /testpath"
}
\ No newline at end of file