summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam Scholten2025-09-11 16:06:10 +1000
committerSam Scholten2025-09-11 16:06:10 +1000
commita7115770e9e377689d9996abe32a28e8db87429d (patch)
tree27d08eb347a8b38aeb47b7eb51050a85ff4c7876 /tests
downloaddrestic-a7115770e9e377689d9996abe32a28e8db87429d.tar.gz
drestic-a7115770e9e377689d9996abe32a28e8db87429d.zip
init
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.bats39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/basic.bats b/tests/basic.bats
new file mode 100644
index 0000000..de4413d
--- /dev/null
+++ b/tests/basic.bats
@@ -0,0 +1,39 @@
+#!/usr/bin/env bats
+
+@test "all scripts have valid bash syntax" {
+ for script in *.sh; do # Assuming main scripts are in root
+ run bash -n "$script"
+ [ "$status" -eq 0 ]
+ done
+}
+
+@test "required commands exist" {
+ for cmd in restic rclone curl git; do
+ run command -v "$cmd"
+ [ "$status" -eq 0 ]
+ done
+}
+
+@test "systemd files have correct syntax" {
+ for file in systemd/*.{service,timer}; do
+ # Create a temporary file for verification to replace placeholders
+ local temp_file=$(mktemp)
+ sed -e 's|/path/to/be/replaced/restic_backup.sh|/usr/local/bin/restic_backup.sh|' \
+ -e 's|# Environment variable will be set by setup.sh based on scope|Environment="RESTIC_ENV_FILE=/tmp/dummy_env"|' \
+ "$file" >"$temp_file"
+
+ run systemd-analyze verify "$temp_file"
+ # systemd-analyze outputs to stderr, so check stderr for success/failure
+ # Check status and ensure no critical errors in stderr
+ local systemd_analyze_output="$(output)"
+ local systemd_analyze_error="$(error)"
+
+ # Ignore the KillMode=none warning from other systemd units if present
+ systemd_analyze_error=$(echo "$systemd_analyze_error" | grep -v "Unit uses KillMode=none")
+
+ if [ "$status" -ne 0 ] && [ -n "$systemd_analyze_error" ] && [[ "$systemd_analyze_error" != *"not available"* ]]; then
+ fail "systemd-analyze failed for $file. Output: $systemd_analyze_output\nError: $systemd_analyze_error"
+ fi
+ rm "$temp_file"
+ done
+}