1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)
}
}
|