blob: bff45e1b75d42135211974813274b764e6323df3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#!/usr/bin/env bash
# ==============================================================================
# Dry-Run Mode Tests
# ==============================================================================
source "$(dirname "${BASH_SOURCE[0]}")/../lib/test_helpers.sh"
# ------------------------------------------------------------------------------
# Test: Dry-run doesn't create backup directory
# ------------------------------------------------------------------------------
test_dryrun_no_directory_creation() {
setup_test_env
create_test_config
create_test_includes
create_test_excludes
# Remove backup dir to verify it's not created
rmdir "$TEST_BACKUP_DIR"
local output
output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
# Backup directory should NOT be created in dry-run mode
assert_dir_not_exists "$TEST_BACKUP_DIR/$HOSTNAME" "backup dir should not be created in dryrun" || {
teardown_test_env
return 1
}
teardown_test_env
}
# ------------------------------------------------------------------------------
# Test: Dry-run shows what would be transferred
# ------------------------------------------------------------------------------
test_dryrun_shows_transfer_info() {
setup_test_env
create_test_config
create_test_includes
create_test_excludes
# Create the backup directory structure for dryrun to work
mkdir -p "$TEST_BACKUP_DIR/$HOSTNAME/latest"
local output
output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
teardown_test_env
# Should show syncing messages
assert_contains "$output" "Syncing" "should show syncing info" || return 1
# Should show dry run message
assert_contains "$output" "Dry run complete" "should show dryrun complete message" || return 1
}
# ------------------------------------------------------------------------------
# Test: Dry-run shows command to run actual backup
# ------------------------------------------------------------------------------
test_dryrun_shows_actual_command() {
setup_test_env
create_test_config
create_test_includes
create_test_excludes
mkdir -p "$TEST_BACKUP_DIR/$HOSTNAME/latest"
local output
output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
teardown_test_env
# Should show how to run actual backup
assert_contains "$output" "sudo rsyncshot manual 1" "should show actual command" || return 1
}
# ------------------------------------------------------------------------------
# Test: Dry-run doesn't create snapshots
# ------------------------------------------------------------------------------
test_dryrun_no_snapshot_creation() {
setup_test_env
create_test_config
create_test_includes
create_test_excludes
mkdir -p "$TEST_BACKUP_DIR/$HOSTNAME/latest"
local output
output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
# Should not create manual.0 snapshot
assert_dir_not_exists "$TEST_BACKUP_DIR/$HOSTNAME/manual.0" "snapshot should not be created in dryrun" || {
teardown_test_env
return 1
}
teardown_test_env
}
# ------------------------------------------------------------------------------
# Run tests
# ------------------------------------------------------------------------------
run_dryrun_tests() {
echo ""
echo "Running dry-run tests..."
echo "------------------------------------------------------------"
run_test "dry-run doesn't create backup directory" test_dryrun_no_directory_creation
run_test "dry-run shows transfer info" test_dryrun_shows_transfer_info
run_test "dry-run shows actual command" test_dryrun_shows_actual_command
run_test "dry-run doesn't create snapshots" test_dryrun_no_snapshot_creation
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
run_dryrun_tests
print_summary
fi
|