From a80ad2b4691d0df63f68c6977ee18444e7bb752f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 18 Jun 2026 08:05:32 +0300 Subject: ik0 replace remaining test seams with DI --- internal/askcli/dispatch_test.go | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'internal/askcli/dispatch_test.go') diff --git a/internal/askcli/dispatch_test.go b/internal/askcli/dispatch_test.go index 2b00a0e..589e956 100644 --- a/internal/askcli/dispatch_test.go +++ b/internal/askcli/dispatch_test.go @@ -5,11 +5,9 @@ import ( "context" "io" "os" - "path/filepath" "reflect" "strings" "testing" - "time" ) func TestDispatcher_Help(t *testing.T) { @@ -45,14 +43,7 @@ func TestDispatcher_Help(t *testing.T) { func TestDispatcher_DefaultsInvalidSubcommandToAdd(t *testing.T) { dir := t.TempDir() - oldRoot := taskAliasCacheRoot - oldNow := nowTaskAliasCache - taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } - nowTaskAliasCache = func() time.Time { return time.Date(2026, 4, 22, 12, 0, 0, 0, time.UTC) } - defer func() { - taskAliasCacheRoot = oldRoot - nowTaskAliasCache = oldNow - }() + t.Setenv("XDG_CACHE_HOME", dir) tests := []struct { name string @@ -136,14 +127,7 @@ func TestDispatcher_CompleteUUIDsSubcommand(t *testing.T) { // Use a temp dir for the alias cache so this test is hermetic and does // not depend on cache state left by other tests. dir := t.TempDir() - oldRoot := taskAliasCacheRoot - oldNow := nowTaskAliasCache - taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } - nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 27, 12, 0, 0, 0, time.UTC) } - defer func() { - taskAliasCacheRoot = oldRoot - nowTaskAliasCache = oldNow - }() + t.Setenv("XDG_CACHE_HOME", dir) d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if strings.Join(args, " ") != "status:pending export" { @@ -168,14 +152,7 @@ func TestDispatcher_CompleteUUIDsSubcommand(t *testing.T) { func TestDispatcher_CompleteAliasesSubcommand(t *testing.T) { dir := t.TempDir() - oldRoot := taskAliasCacheRoot - oldNow := nowTaskAliasCache - taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } - nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 27, 12, 0, 0, 0, time.UTC) } - defer func() { - taskAliasCacheRoot = oldRoot - nowTaskAliasCache = oldNow - }() + t.Setenv("XDG_CACHE_HOME", dir) d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if strings.Join(args, " ") != "status:pending export" { @@ -448,14 +425,7 @@ func TestDispatcher_NoAgentPrefix_StripsScopePrefix(t *testing.T) { func TestDispatcher_AllSubcommandsReachExecutor(t *testing.T) { dir := t.TempDir() - oldRoot := taskAliasCacheRoot - oldNow := nowTaskAliasCache - taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } - nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 27, 12, 0, 0, 0, time.UTC) } - defer func() { - taskAliasCacheRoot = oldRoot - nowTaskAliasCache = oldNow - }() + t.Setenv("XDG_CACHE_HOME", dir) taskJSONFor := func(uuid string) string { return `[{"uuid":"` + uuid + `","description":"Test","status":"pending","priority":"M","tags":[],"urgency":10,"depends":[]}]` -- cgit v1.2.3