summaryrefslogtreecommitdiff
path: root/internal/askcli/command_dep_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/askcli/command_dep_test.go')
-rw-r--r--internal/askcli/command_dep_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/internal/askcli/command_dep_test.go b/internal/askcli/command_dep_test.go
new file mode 100644
index 0000000..c77bc1a
--- /dev/null
+++ b/internal/askcli/command_dep_test.go
@@ -0,0 +1,75 @@
+package askcli
+
+import (
+ "bytes"
+ "context"
+ "io"
+ "strings"
+ "testing"
+)
+
+func TestHandleDep_AddSuccess(t *testing.T) {
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"dep", "add", "uuid-1", "uuid-2"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("dep add code = %d, want 0", code)
+ }
+ if !strings.Contains(stdout.String(), "ok") || !strings.Contains(stdout.String(), "uuid-1") {
+ t.Fatalf("stdout = %q, want ok + uuid", stdout.String())
+ }
+}
+
+func TestHandleDep_RmSuccess(t *testing.T) {
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"dep", "rm", "uuid-1", "uuid-2"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("dep rm code = %d, want 0", code)
+ }
+}
+
+func TestHandleDep_ListSuccess(t *testing.T) {
+ jsonData := `[{"uuid":"uuid-1","description":"Task","status":"pending","priority":"M","tags":[],"urgency":10,"depends":["dep-1","dep-2"]}]`
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ if args[0] == "info" {
+ io.WriteString(stdout, jsonData)
+ }
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"dep", "list", "uuid-1"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("dep list code = %d, want 0", code)
+ }
+ output := stdout.String()
+ if !strings.Contains(output, "dep-1") || !strings.Contains(output, "dep-2") {
+ t.Fatalf("stdout = %q, want deps", output)
+ }
+}
+
+func TestHandleDep_UnknownOp(t *testing.T) {
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"dep", "unknown", "uuid-1", "uuid-2"}, nil, &stdout, &stderr)
+ if code != 1 {
+ t.Fatalf("dep unknown code = %d, want 1", code)
+ }
+}
+
+func TestHandleDep_NumericUUID(t *testing.T) {
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"dep", "add", "123", "uuid-2"}, nil, &stdout, &stderr)
+ if code != 1 {
+ t.Fatalf("dep add code = %d, want 1 for numeric UUID", code)
+ }
+}