From d3586ad2b2b140435055c349393154ae7cfffaea Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 27 Mar 2026 07:18:04 +0200 Subject: task 3a4c0f14-16ad-487f-af7c-bd99ee6464e6: use pointer Dispatcher receivers --- internal/askcli/dispatch_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'internal/askcli/dispatch_test.go') diff --git a/internal/askcli/dispatch_test.go b/internal/askcli/dispatch_test.go index cd83e48..48c3e55 100644 --- a/internal/askcli/dispatch_test.go +++ b/internal/askcli/dispatch_test.go @@ -123,6 +123,34 @@ func TestDispatcher_FishSubcommandRejectsExtraArgs(t *testing.T) { } } +func TestDispatcher_DispatchPersistsJSONFlagOnDispatcher(t *testing.T) { + 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" { + t.Fatalf("args = %v, want list export args", args) + } + _, _ = io.WriteString(stdout, `[]`) + return 0, nil + }}) + + var stdout, stderr bytes.Buffer + code, err := d.Dispatch(context.Background(), []string{"--json", "list"}, nil, &stdout, &stderr) + if err != nil { + t.Fatalf("Dispatch returned error: %v", err) + } + if code != 0 { + t.Fatalf("Dispatch code = %d, want 0", code) + } + if !d.jsonOutput { + t.Fatal("Dispatch did not persist jsonOutput on the dispatcher") + } + if got := stdout.String(); got != "[]\n" { + t.Fatalf("stdout = %q, want JSON output", got) + } + if stderr.Len() != 0 { + t.Fatalf("stderr = %q, want empty", stderr.String()) + } +} + func TestDispatcher_AllSubcommandsReachExecutor(t *testing.T) { subcommands := []string{} subcommandArgs := map[string][]string{ -- cgit v1.2.3