summaryrefslogtreecommitdiff
path: root/internal/askcli/command_start_deps_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_start_deps_test.go
parent4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b (diff)
ik0 replace remaining test seams with DI
Diffstat (limited to 'internal/askcli/command_start_deps_test.go')
-rw-r--r--internal/askcli/command_start_deps_test.go37
1 files changed, 9 insertions, 28 deletions
diff --git a/internal/askcli/command_start_deps_test.go b/internal/askcli/command_start_deps_test.go
index 9ba197b..929eabc 100644
--- a/internal/askcli/command_start_deps_test.go
+++ b/internal/askcli/command_start_deps_test.go
@@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
- "path/filepath"
"strings"
"testing"
"time"
@@ -12,15 +11,8 @@ import (
func TestHandleStart_BlockedWhenDependencyNotCompleted(t *testing.T) {
dir := t.TempDir()
- oldRoot := taskAliasCacheRoot
- oldNow := nowTaskAliasCache
fixedNow := time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC)
- taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
- nowTaskAliasCache = func() time.Time { return fixedNow }
- defer func() {
- taskAliasCacheRoot = oldRoot
- nowTaskAliasCache = oldNow
- }()
+ deps := testTaskAliasCacheDeps(dir, &fixedNow)
writeTaskAliasCacheForTest(t, taskAliasCache{
NextID: 2,
@@ -28,7 +20,7 @@ func TestHandleStart_BlockedWhenDependencyNotCompleted(t *testing.T) {
{UUID: "main-uuid", Alias: "0", CreatedAt: fixedNow},
{UUID: "dep-uuid", Alias: "1", CreatedAt: fixedNow},
},
- })
+ }, deps)
var startCalls int
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
@@ -47,6 +39,7 @@ func TestHandleStart_BlockedWhenDependencyNotCompleted(t *testing.T) {
return 1, nil
}
}})
+ d.aliasCache = deps
var stdout, stderr bytes.Buffer
code, _ := d.Dispatch(context.Background(), []string{"start", "main-uuid"}, &bytes.Buffer{}, &stdout, &stderr)
@@ -66,15 +59,8 @@ func TestHandleStart_BlockedWhenDependencyNotCompleted(t *testing.T) {
func TestHandleStart_AllowedWhenDependencyCompleted(t *testing.T) {
dir := t.TempDir()
- oldRoot := taskAliasCacheRoot
- oldNow := nowTaskAliasCache
fixedNow := time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC)
- taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
- nowTaskAliasCache = func() time.Time { return fixedNow }
- defer func() {
- taskAliasCacheRoot = oldRoot
- nowTaskAliasCache = oldNow
- }()
+ deps := testTaskAliasCacheDeps(dir, &fixedNow)
writeTaskAliasCacheForTest(t, taskAliasCache{
NextID: 2,
@@ -82,7 +68,7 @@ func TestHandleStart_AllowedWhenDependencyCompleted(t *testing.T) {
{UUID: "main-uuid", Alias: "0", CreatedAt: fixedNow},
{UUID: "dep-uuid", Alias: "1", CreatedAt: fixedNow},
},
- })
+ }, deps)
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
switch {
@@ -99,6 +85,7 @@ func TestHandleStart_AllowedWhenDependencyCompleted(t *testing.T) {
return 1, nil
}
}})
+ d.aliasCache = deps
var stdout, stderr bytes.Buffer
code, _ := d.Dispatch(context.Background(), []string{"start", "main-uuid"}, &bytes.Buffer{}, &stdout, &stderr)
@@ -112,15 +99,8 @@ func TestHandleStart_AllowedWhenDependencyCompleted(t *testing.T) {
func TestHandleStart_CompletedStatusIsCaseInsensitive(t *testing.T) {
dir := t.TempDir()
- oldRoot := taskAliasCacheRoot
- oldNow := nowTaskAliasCache
fixedNow := time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC)
- taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil }
- nowTaskAliasCache = func() time.Time { return fixedNow }
- defer func() {
- taskAliasCacheRoot = oldRoot
- nowTaskAliasCache = oldNow
- }()
+ deps := testTaskAliasCacheDeps(dir, &fixedNow)
writeTaskAliasCacheForTest(t, taskAliasCache{
NextID: 2,
@@ -128,7 +108,7 @@ func TestHandleStart_CompletedStatusIsCaseInsensitive(t *testing.T) {
{UUID: "main-uuid", Alias: "0", CreatedAt: fixedNow},
{UUID: "dep-uuid", Alias: "1", CreatedAt: fixedNow},
},
- })
+ }, deps)
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
switch {
@@ -145,6 +125,7 @@ func TestHandleStart_CompletedStatusIsCaseInsensitive(t *testing.T) {
return 1, nil
}
}})
+ d.aliasCache = deps
var stdout, stderr bytes.Buffer
code, _ := d.Dispatch(context.Background(), []string{"start", "main-uuid"}, &bytes.Buffer{}, &stdout, &stderr)