diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 03:10:55 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 03:10:55 +0200 |
| commit | 1fc1611fa99993cab5dc8bf0844183285296e3b2 (patch) | |
| tree | c5c9b8b5abac5b5d4c0d56ed90b0580184cc4383 /cmd/hexai-tmux-action/main_test.go | |
| parent | 12090f25a3677291863dbb80277bdad3eaec0324 (diff) | |
Release v0.24.0v0.24.0
Bring unit test coverage from ~75% to 85.1% project-wide. All internal
packages now exceed 80% coverage. Refactored cmd entrypoints to extract
testable run() functions with injectable seams.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'cmd/hexai-tmux-action/main_test.go')
| -rw-r--r-- | cmd/hexai-tmux-action/main_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/cmd/hexai-tmux-action/main_test.go b/cmd/hexai-tmux-action/main_test.go new file mode 100644 index 0000000..8abd420 --- /dev/null +++ b/cmd/hexai-tmux-action/main_test.go @@ -0,0 +1,63 @@ +package main + +import ( + "context" + "errors" + "io" + "testing" + + "codeberg.org/snonux/hexai/internal/hexaiaction" +) + +func TestRun_DelegatesToRunCommand(t *testing.T) { + old := runCommand + t.Cleanup(func() { runCommand = old }) + + var gotOpts hexaiaction.Options + runCommand = func(_ context.Context, opts hexaiaction.Options, _ io.Reader, _, _ io.Writer) error { + gotOpts = opts + return nil + } + + opts := actionOptions{ + infile: "in.txt", outfile: "out.txt", + tmuxSplit: "h", tmuxPercent: 50, + } + if err := run(opts, nil, nil, nil); err != nil { + t.Fatalf("run: %v", err) + } + if gotOpts.Infile != "in.txt" || gotOpts.Outfile != "out.txt" { + t.Fatalf("unexpected opts: %+v", gotOpts) + } + if gotOpts.TmuxSplit != "h" || gotOpts.TmuxPercent != 50 { + t.Fatalf("unexpected tmux opts: %+v", gotOpts) + } +} + +func TestRun_WithConfigPath(t *testing.T) { + old := runCommand + t.Cleanup(func() { runCommand = old }) + + runCommand = func(_ context.Context, _ hexaiaction.Options, _ io.Reader, _, _ io.Writer) error { + return nil + } + + opts := actionOptions{configPath: " /tmp/test.toml ", tmuxSplit: "v", tmuxPercent: 33} + if err := run(opts, nil, nil, nil); err != nil { + t.Fatalf("run: %v", err) + } +} + +func TestRun_Error(t *testing.T) { + old := runCommand + t.Cleanup(func() { runCommand = old }) + + wantErr := errors.New("action failed") + runCommand = func(_ context.Context, _ hexaiaction.Options, _ io.Reader, _, _ io.Writer) error { + return wantErr + } + + if err := run(actionOptions{}, nil, nil, nil); !errors.Is(err, wantErr) { + t.Fatalf("expected error, got: %v", err) + } +} |
