diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-03-15 23:57:44 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-03-16 00:01:25 +0900 |
| commit | 6e7ddb2d2ec6b163dc2c178bc4d73b5943f51206 (patch) | |
| tree | 37ffe1564782377c1983909362ed6109c3f06b28 /helper/helper_test.go | |
| parent | bac4e67867faa7d8274b684575140a65827d3a4c (diff) | |
helper: eliminate commandContext replacement
This is done more cleanly by modifying Args in cmdF.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper/helper_test.go')
| -rw-r--r-- | helper/helper_test.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/helper/helper_test.go b/helper/helper_test.go index 3274fe5c..4bc98b5e 100644 --- a/helper/helper_test.go +++ b/helper/helper_test.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "os/exec" + "io" "strconv" "strings" "testing" @@ -36,7 +36,8 @@ func argF(argsFd, statFd int) []string { } func argFChecked(argsFd, statFd int) (args []string) { - args = make([]string, 0, 4) + args = make([]string, 0, 6) + args = append(args, "-test.run=TestHelperStub", "--") if argsFd > -1 { args = append(args, "--args", strconv.Itoa(argsFd)) } @@ -47,13 +48,14 @@ func argFChecked(argsFd, statFd int) (args []string) { } // this function tests an implementation of the helper.Helper interface -func testHelper(t *testing.T, createHelper func(ctx context.Context, cmdF func(cmd *exec.Cmd), stat bool) helper.Helper) { - helper.InternalReplaceExecCommand(t) - +func testHelper(t *testing.T, + createHelper func(ctx context.Context, setOutput func(stdoutP, stderrP *io.Writer), stat bool) helper.Helper, + prefix string, +) { t.Run("start helper with status channel and wait", func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) stdout, stderr := new(strings.Builder), new(strings.Builder) - h := createHelper(ctx, func(cmd *exec.Cmd) { cmd.Stdout, cmd.Stderr = stdout, stderr }, true) + h := createHelper(ctx, func(stdoutP, stderrP *io.Writer) { *stdoutP, *stderrP = stdout, stderr }, true) t.Run("wait not yet started helper", func(t *testing.T) { defer func() { @@ -75,7 +77,7 @@ func testHelper(t *testing.T, createHelper func(ctx context.Context, cmdF func(c cancel() t.Run("start already started helper", func(t *testing.T) { - wantErr := "exec: already started" + wantErr := prefix + ": already started" if err := h.Start(); err != nil && err.Error() != wantErr { t.Errorf("Start: error = %v, wantErr %v", err, wantErr) @@ -108,7 +110,7 @@ func testHelper(t *testing.T, createHelper func(ctx context.Context, cmdF func(c ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() stdout, stderr := new(strings.Builder), new(strings.Builder) - h := createHelper(ctx, func(cmd *exec.Cmd) { cmd.Stdout, cmd.Stderr = stdout, stderr }, false) + h := createHelper(ctx, func(stdoutP, stderrP *io.Writer) { *stdoutP, *stderrP = stdout, stderr }, false) if err := h.Start(); err != nil { t.Errorf("Start() error = %v", |
