Add comprehensive unit tests (issues #12-#15) #30

Merged
qwc merged 1 commit from testing/unit-tests into main 2026-02-02 16:17:42 +01:00
Owner

Summary

  • Config tests (config_test.go): CreateViper idempotency, Settings.validate with valid/empty/relative paths, Load with valid YAML, missing config (panic), relative path (panic)
  • Runs tests (backup_test.go): RegisterRun, Save/Load round-trip through JSON, LastRun edge cases, legacy string-based DB format, map-based DB format, bad types, bad timestamps
  • defaultCallback tests (cmd/backive/main_test.go): All early-return paths — no ACTION, wrong ACTION, no UUID, unknown UUID, no matching backups, CanRun failure
  • Error-path tests: Database read/write errors and panics, mount/unmount/sync failures, accept errors, invalid JSON on socket, non-udev requests, chown failures, path traversal rejection, script execution failures
  • Bug fix: database.go Load() now uses mockable mockOsStat/mockOsIsNotExist instead of direct os.Stat/os.IsNotExist calls, consistent with the pattern used elsewhere

Coverage: 84.3% (backive package), 38.5% (cmd/backive package)

Closes #12, closes #13, closes #14, closes #15

## Summary - **Config tests** (`config_test.go`): CreateViper idempotency, Settings.validate with valid/empty/relative paths, Load with valid YAML, missing config (panic), relative path (panic) - **Runs tests** (`backup_test.go`): RegisterRun, Save/Load round-trip through JSON, LastRun edge cases, legacy string-based DB format, map-based DB format, bad types, bad timestamps - **defaultCallback tests** (`cmd/backive/main_test.go`): All early-return paths — no ACTION, wrong ACTION, no UUID, unknown UUID, no matching backups, CanRun failure - **Error-path tests**: Database read/write errors and panics, mount/unmount/sync failures, accept errors, invalid JSON on socket, non-udev requests, chown failures, path traversal rejection, script execution failures - **Bug fix**: `database.go` Load() now uses mockable `mockOsStat`/`mockOsIsNotExist` instead of direct `os.Stat`/`os.IsNotExist` calls, consistent with the pattern used elsewhere **Coverage**: 84.3% (backive package), 38.5% (cmd/backive package) Closes #12, closes #13, closes #14, closes #15
Add comprehensive unit tests for config, runs, callbacks, and error paths
All checks were successful
Go / build (pull_request) Successful in 5m28s
103a909bcb
- Add config_test.go: tests for CreateViper, Settings.validate, Load (valid/missing/invalid)
- Extend backup_test.go: tests for RegisterRun, Save/Load round-trip, LastRun,
  error paths (chown failure, path traversal, unmounted device, script failure),
  legacy/map DB format loading, and FindBackupsForDevice
- Add cmd/backive/main_test.go: tests for defaultCallback flow control
  (no action, wrong action, no UUID, unknown UUID, no backups, CanRun failure)
- Extend database_test.go: tests for file-not-exist, read error, invalid JSON,
  write error, and save/load round-trip; fix Load() to use mockable os.Stat
- Extend device_test.go: tests for mount failure, unmount failure, sync failure,
  unmount when not mounted
- Extend events_test.go: tests for accept error, invalid JSON, non-udev request;
  add badJSONConn and jsonConn helper types

Coverage: 84.3% (backive pkg), 38.5% (cmd/backive pkg).

Closes #12, closes #13, closes #14, closes #15

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
qwc merged commit 23d9bfa167 into main 2026-02-02 16:17:42 +01:00
qwc deleted branch testing/unit-tests 2026-02-02 16:17:42 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
qwc-open/backive!30
No description provided.