From 5fcf5f1c24069bad389293525b54398f618de6b9 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 9 Aug 2026 08:52:46 +0200 Subject: [PATCH] add bats test tags --- tests/backup_tests.bats | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index f216b0a..7a97e54 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -31,6 +31,7 @@ teardown() { unset RSYNC_LOG } +# bats test_tags=backup:start @test "success start message" { run main @@ -38,6 +39,7 @@ teardown() { assert_line --index 0 "⭐ START: backup" } +# bats test_tags=backup:start,backup:cmd @test "failure yq command not found" { command() { return 1 @@ -50,6 +52,7 @@ teardown() { assert_line --index 1 "❌ ERROR: command yq not found" } +# bats test_tags=backup:start,backup:cmd @test "failure jq command not found" { command() { [ "$2" != "jq" ] || return 1 @@ -62,6 +65,7 @@ teardown() { assert_line --index 1 "❌ ERROR: command jq not found" } +# bats test_tags=backup:start,backup:cmd @test "failure rsync command not found" { command() { [ "$2" != "rsync" ] || return 1 @@ -74,6 +78,7 @@ teardown() { assert_line --index 1 "❌ ERROR: command rsync not found" } +# bats test_tags=backup:start,backup:cmd @test "failure ssh command not found" { command() { [ "$2" != "ssh" ] || return 1 @@ -86,6 +91,7 @@ teardown() { assert_line --index 1 "❌ ERROR: command ssh not found" } +# bats test_tags=backup:start,backup:config @test "failure config.yaml not found" { exists_config_file() { errlog "file config.yaml not found" @@ -99,6 +105,7 @@ teardown() { assert_line --index 1 "❌ ERROR: file config.yaml not found" } +# bats test_tags=backup:start,backup:config @test "failure load config.yaml" { yq() { return 1 @@ -111,6 +118,7 @@ teardown() { assert_line --index 1 "❌ ERROR: failed to load src/config-example.yaml" } +# bats test_tags=backup:start,backup:config @test "failure no backup path in config" { yq() { echo '{}' @@ -123,6 +131,7 @@ teardown() { assert_line --index 1 "❌ ERROR: src/config-example.yaml missing backup_path" } +# bats test_tags=backup:start,backup:config @test "failure no backup name in config" { yq() { echo '{"backup_path": "path"}' @@ -136,6 +145,7 @@ teardown() { assert_line --index 2 "❌ ERROR: src/config-example.yaml missing backup_name" } +# bats test_tags=backup:start,backup:config @test "failure no backup count in config" { yq() { echo '{ @@ -153,6 +163,7 @@ teardown() { assert_line --index 3 "❌ ERROR: src/config-example.yaml missing backup_count" } +# bats test_tags=backup:start,backup:config @test "failure no machines in config" { yq() { echo '{ @@ -172,6 +183,7 @@ teardown() { assert_line --index 4 "❌ ERROR: src/config-example.yaml missing machines" } +# bats test_tags=backup:info @test "success info backup count" { create_backup_dir() { : @@ -196,6 +208,7 @@ teardown() { assert_line --index 8 "✅ SUCCESS: backup" } +# bats test_tags=backup:info @test "success last backup dir path info" { create_backup_dir() { : @@ -224,6 +237,7 @@ teardown() { assert_line --index 9 "✅ SUCCESS: backup" } +# bats test_tags=backup:info @test "success new backup folder info" { create_backup_dir() { : @@ -249,6 +263,7 @@ teardown() { assert_line --index 8 "✅ SUCCESS: backup" } +# bats test_tags=backup:info @test "success new backup folder with number 02 info" { mkdir --parents "build/2000-01-01_01_backup" create_backup_dir() { @@ -277,6 +292,7 @@ teardown() { rmdir "build/2000-01-01_01_backup" } +# bats test_tags=backup:info @test "success create backup folder" { backup_machines() { : @@ -301,6 +317,7 @@ teardown() { [ -d "build/2000-01-01_01_backup" ] } +# bats test_tags=backup:info @test "success create backup folder latest number" { mkdir --parents "build/2000-01-01_35_backup" backup_machines() { @@ -329,6 +346,7 @@ teardown() { rmdir "build/2000-01-01_36_backup" } +# bats test_tags=backup:info @test "success create backup folder latest number with other date" { mkdir --parents "build/1999-12-31_35_backup" backup_machines() { @@ -357,6 +375,7 @@ teardown() { rmdir "build/2000-01-01_01_backup" } +# bats test_tags=backup:info @test "success backup machines" { machine_backup_pathes() { : @@ -386,6 +405,7 @@ teardown() { [ -d "build/2000-01-01_01_backup/testpc2" ] } +# bats test_tags=backup:info @test "success backup machine pathes" { path_backup() { : @@ -423,6 +443,7 @@ teardown() { assert_line --index 24 "✅ SUCCESS: backup" } +# bats test_tags=backup:info @test "failure backup machine pathes is null" { yq() { echo '{ @@ -449,6 +470,7 @@ teardown() { assert_line --index 8 "❌ ERROR: missing pathes for machine testpc1" } +# bats test_tags=backup:info @test "failure backup machine path no remote user" { yq() { echo '{ @@ -479,6 +501,7 @@ teardown() { assert_line --index 10 "❌ ERROR: missing remote user for testpc1" } +# bats test_tags=backup:info @test "failure backup machine path no host" { yq() { echo '{ @@ -510,6 +533,7 @@ teardown() { assert_line --index 10 "❌ ERROR: missing host for testpc1" } +# bats test_tags=backup:info @test "failure backup machine path no port" { yq() { echo '{ @@ -542,6 +566,7 @@ teardown() { assert_line --index 10 "❌ ERROR: missing port for testpc1" } +# bats test_tags=backup:info @test "success backup machine path excludes info" { run main @@ -561,6 +586,7 @@ teardown() { assert_line --partial "✅ SUCCESS: backup" } +# bats test_tags=backup:info @test "success backup machine path without excludes" { yq() { echo '{ @@ -599,6 +625,7 @@ teardown() { assert_line --index 13 "✅ SUCCESS: backup" } +# bats test_tags=backup:rsync @test "success backup machine path rsync parameters" { RSYNC_LOG_RUNS="1" @@ -623,6 +650,7 @@ teardown() { } +# bats test_tags=backup:rsync @test "success backup machine path rsync parameters without excludes" { RSYNC_LOG_RUNS="3" run main @@ -643,6 +671,7 @@ teardown() { assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/testpc2" } +# bats test_tags=backup:rsync @test "success backup machine path rsync localhost" { RSYNC_LOG_RUNS="4" run main @@ -663,6 +692,7 @@ teardown() { assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/onlylocal" } +# bats test_tags=backup:rsync @test "success backup machine path rsync localhost with hard links" { mkdir --parents "build/1999-12-31_01_backup" @@ -684,8 +714,10 @@ teardown() { assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "--link-dest=build/1999-12-31_01_backup/onlylocal" assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "/home/local" assert_equal "$(awk 'NR==12 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/onlylocal" + rmdir "build/1999-12-31_01_backup" } +# bats test_tags=backup:rsync @test "failure backup machine path rsync failed" { rsync() { return 1 @@ -697,6 +729,7 @@ teardown() { assert_line --partial "❌ ERROR: could not backup testpc1 with path /etc" } +# bats test_tags=backup:info,backup:cleanup @test "success show current backup count" { mkdir --parents "build/1999-12-24_01_backup" mkdir --parents "build/1999-12-30_01_backup" @@ -715,6 +748,7 @@ teardown() { rm --recursive --force "build/2000-01-01_02_backup" } +# bats test_tags=backup:info,backup:cleanup @test "success no backup to cleanup info" { run main @@ -723,6 +757,7 @@ teardown() { assert_line --partial "ℹ️ INFO: no backup to cleanup" } +# bats test_tags=backup:info,backup:cleanup @test "success cleanup one backup" { local num= for i in {1..5}; do @@ -750,6 +785,7 @@ teardown() { rmdir build/1999-* } +# bats test_tags=backup:info,backup:cleanup @test "success cleanup four backup" { local num= for i in {1..5}; do @@ -784,6 +820,7 @@ teardown() { rmdir build/1999-* } +# bats test_tags=backup:info,backup:cleanup @test "success cleanup four backup on same date" { local num= for i in {1..18}; do -- 2.47.3