diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-18 07:45:37 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-18 07:45:37 +0300 |
| commit | 4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b (patch) | |
| tree | 2dc708cbb95975d34084eb5afd376871caa13e27 /internal/askcli/command_watch.go | |
| parent | ece7dcfd232b780f5650326c8ac2379ca70387d4 (diff) | |
ik0 replace test seams with dependency injection
Diffstat (limited to 'internal/askcli/command_watch.go')
| -rw-r--r-- | internal/askcli/command_watch.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/internal/askcli/command_watch.go b/internal/askcli/command_watch.go index 8d8e35f..0e0a678 100644 --- a/internal/askcli/command_watch.go +++ b/internal/askcli/command_watch.go @@ -30,7 +30,10 @@ func (t realWatchTicker) Stop() { t.ticker.Stop() } -var newWatchTicker = func(interval time.Duration) watchTicker { +// newRealWatchTicker is the default watchTicker factory wired into a +// Dispatcher by NewDispatcher. It is injected as Dispatcher.newTicker so tests +// can substitute a fake ticker instead of mutating package state. +func newRealWatchTicker(interval time.Duration) watchTicker { return realWatchTicker{ticker: time.NewTicker(interval)} } @@ -63,7 +66,7 @@ func (d *Dispatcher) handleWatch(ctx context.Context, args []string, stdout, std return 1, nil } - ticker := newWatchTicker(watchInterval) + ticker := d.newTicker(watchInterval) defer ticker.Stop() var lastOutput []byte |
