From 4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 18 Jun 2026 07:45:37 +0300 Subject: ik0 replace test seams with dependency injection --- internal/askcli/command_watch.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'internal/askcli/command_watch.go') 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 -- cgit v1.2.3