From 8b22a36d1c068f9baee68799b0c1f51ecb999e9d Mon Sep 17 00:00:00 2001 From: Bernhard Guillon Date: Mon, 6 Jul 2026 21:26:29 +0200 Subject: Add watcher tests, refactor watch() to accept context - Added watcher_test.go: 10 tests covering create, write, remove, rename, ignored files, debouncing, directory creation/removal, and manifest updates - Refactored watch() to accept context.Context for clean cancellation - Added signal handling (SIGINT/SIGTERM) for graceful shutdown in main.go - Fixed test expectations (version two = 11 bytes, not 10) --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 345436f..436c7b7 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,12 @@ package main import ( + "context" "flag" "log" + "os" + "os/signal" + "syscall" ) var ( @@ -31,7 +35,10 @@ func main() { log.Fatalf("initial sync failed: %v", err) } - if err := watch(*hostDir, *dataDir, manifest, rules, *dryRun, *verbose); err != nil { + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + defer cancel() + + if err := watch(ctx, *hostDir, *dataDir, manifest, rules, *dryRun, *verbose); err != nil { log.Fatalf("watcher failed: %v", err) } } -- cgit v1.2.3