diff options
Diffstat (limited to 'internal/watcher')
| -rw-r--r-- | internal/watcher/config.go | 11 | ||||
| -rw-r--r-- | internal/watcher/doc.go | 7 | ||||
| -rw-r--r-- | internal/watcher/watcher.go | 21 | ||||
| -rw-r--r-- | internal/watcher/watcher_test.go | 31 |
4 files changed, 70 insertions, 0 deletions
diff --git a/internal/watcher/config.go b/internal/watcher/config.go new file mode 100644 index 0000000..ad12d0c --- /dev/null +++ b/internal/watcher/config.go @@ -0,0 +1,11 @@ +package watcher + +import "time" + +// Configures a filesystem watcher +type Config struct { + Roots []string + + Debounce time.Duration + OnChange func() +} diff --git a/internal/watcher/doc.go b/internal/watcher/doc.go new file mode 100644 index 0000000..95801aa --- /dev/null +++ b/internal/watcher/doc.go @@ -0,0 +1,7 @@ +// Package watcher watches configured directories for filesystem changes. +// +// The package is intentionally unaware of galleries, thumbnails and HTTP. +// +// Its sole responsibility is detecting filesystem changes and notifying +// the caller through a callback. +package watcher diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go new file mode 100644 index 0000000..5465554 --- /dev/null +++ b/internal/watcher/watcher.go @@ -0,0 +1,21 @@ +package watcher + +import "context" + +type Watcher struct { + config Config +} + +func New(config Config) *Watcher { + return &Watcher{ + config: config, + } +} + +// Run starts the watcher. +// +// Placeholder implementation. +func (w *Watcher) Run(ctx context.Context) error { + <-ctx.Done() + return nil +} diff --git a/internal/watcher/watcher_test.go b/internal/watcher/watcher_test.go new file mode 100644 index 0000000..53c0baa --- /dev/null +++ b/internal/watcher/watcher_test.go @@ -0,0 +1,31 @@ +package watcher + +import ( + "context" + "testing" + "time" +) + +func TestRunReturnsOnContextCancellation(t *testing.T) { + w := New(Config{}) + + ctx, cancel := context.WithCancel(context.Background()) + + done := make(chan error, 1) + + go func() { + done <- w.Run(ctx) + }() + + cancel() + + select { + case err := <-done: + if err != nil { + t.Fatalf("expected nil, got %v", err) + } + + case <-time.After(time.Second): + t.Fatal("watcher did not exit") + } +} |