summaryrefslogtreecommitdiff
path: root/internal/askcli/command_complete_uuids_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-18 08:05:32 +0300
committerPaul Buetow <paul@buetow.org>2026-06-18 08:05:32 +0300
commita80ad2b4691d0df63f68c6977ee18444e7bb752f (patch)
tree6edc47fcc3c929856826432cf3df3394a14934e8 /internal/askcli/command_complete_uuids_test.go
parent4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b (diff)
ik0 replace remaining test seams with DI
Diffstat (limited to 'internal/askcli/command_complete_uuids_test.go')
-rw-r--r--internal/askcli/command_complete_uuids_test.go31
1 files changed, 10 insertions, 21 deletions
diff --git a/internal/askcli/command_complete_uuids_test.go b/internal/askcli/command_complete_uuids_test.go
index 2c1b5fd..b7a2e80 100644
--- a/internal/askcli/command_complete_uuids_test.go
+++ b/internal/askcli/command_complete_uuids_test.go
@@ -13,14 +13,8 @@ import (
func TestHandleCompleteUUIDs_PrintsPendingUUIDs(t *testing.T) {
dir := t.TempDir()
- oldNow := nowTaskAliasCache
- oldRoot := taskAliasCacheRoot
- nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) }
- taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
- defer func() {
- nowTaskAliasCache = oldNow
- taskAliasCacheRoot = oldRoot
- }()
+ now := time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC)
+ deps := testTaskAliasCacheDeps(dir, &now)
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
want := []string{"status:pending", "export"}
@@ -30,6 +24,7 @@ func TestHandleCompleteUUIDs_PrintsPendingUUIDs(t *testing.T) {
_, _ = io.WriteString(stdout, `[{"uuid":"uuid-1","description":"First task"},{"uuid":"uuid-2","description":"Second task"},{"uuid":""}]`)
return 0, nil
}})
+ d.aliasCache = deps
var stdout, stderr bytes.Buffer
code, err := d.handleCompleteUUIDs(context.Background(), nil, &stdout, &stderr)
@@ -48,7 +43,7 @@ func TestHandleCompleteUUIDs_PrintsPendingUUIDs(t *testing.T) {
t.Fatalf("stderr = %q, want empty", stderr.String())
}
- path, err := taskAliasCachePath()
+ path, err := deps.taskAliasCachePath()
if err != nil {
t.Fatalf("taskAliasCachePath: %v", err)
}
@@ -82,11 +77,9 @@ func TestHandleCompleteUUIDs_ParseError(t *testing.T) {
func TestHandleCompleteUUIDs_RecoverFromCorruptAliasCache(t *testing.T) {
dir := t.TempDir()
- oldRoot := taskAliasCacheRoot
- taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
- defer func() { taskAliasCacheRoot = oldRoot }()
+ deps := testTaskAliasCacheDeps(dir, nil)
- path, err := taskAliasCachePath()
+ path, err := deps.taskAliasCachePath()
if err != nil {
t.Fatalf("taskAliasCachePath: %v", err)
}
@@ -104,6 +97,7 @@ func TestHandleCompleteUUIDs_RecoverFromCorruptAliasCache(t *testing.T) {
_, _ = io.WriteString(stdout, `[{"uuid":"uuid-1","description":"Fallback task"}]`)
return 0, nil
}})
+ d.aliasCache = deps
var stdout, stderr bytes.Buffer
code, err := d.handleCompleteUUIDs(context.Background(), nil, &stdout, &stderr)
@@ -168,14 +162,8 @@ func TestTaskCompletionAliasItems_OnlyShortAliases(t *testing.T) {
func TestHandleCompleteAliases_PrintsAliasesOnly(t *testing.T) {
dir := t.TempDir()
- oldNow := nowTaskAliasCache
- oldRoot := taskAliasCacheRoot
- nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) }
- taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
- defer func() {
- nowTaskAliasCache = oldNow
- taskAliasCacheRoot = oldRoot
- }()
+ now := time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC)
+ deps := testTaskAliasCacheDeps(dir, &now)
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
want := []string{"status:pending", "export"}
@@ -185,6 +173,7 @@ func TestHandleCompleteAliases_PrintsAliasesOnly(t *testing.T) {
_, _ = io.WriteString(stdout, `[{"uuid":"uuid-1","description":"First task"},{"uuid":"uuid-2","description":"Second task"},{"uuid":""}]`)
return 0, nil
}})
+ d.aliasCache = deps
var stdout, stderr bytes.Buffer
code, err := d.handleCompleteAliases(context.Background(), nil, &stdout, &stderr)