aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/helper_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-14 18:30:22 +0900
committerOphestra <cat@gensokyo.uk>2025-03-14 18:30:22 +0900
commit7c60a4d8e8baa77b42789c041838fa82dd7d36f9 (patch)
treeb859b33bd4d522229e2b497992ef42243f1b22d7 /helper/helper_test.go
parent4bb5d9780f3c46e942dc778d93c28391caee33c7 (diff)
helper: embed context on creation
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper/helper_test.go')
-rw-r--r--helper/helper_test.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/helper/helper_test.go b/helper/helper_test.go
index 69be474e..363cc04d 100644
--- a/helper/helper_test.go
+++ b/helper/helper_test.go
@@ -46,14 +46,15 @@ func argFChecked(argsFd, statFd int) (args []string) {
}
// this function tests an implementation of the helper.Helper interface
-func testHelper(t *testing.T, createHelper func() helper.Helper) {
+func testHelper(t *testing.T, createHelper func(ctx context.Context) helper.Helper) {
helper.InternalReplaceExecCommand(t)
t.Run("start helper with status channel and wait", func(t *testing.T) {
- h := createHelper()
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ h := createHelper(ctx)
stdout, stderr := new(strings.Builder), new(strings.Builder)
- h.Stdout(stdout).Stderr(stderr)
+ h.SetStdout(stdout).SetStderr(stderr)
t.Run("wait not yet started helper", func(t *testing.T) {
defer func() {
@@ -65,10 +66,8 @@ func testHelper(t *testing.T, createHelper func() helper.Helper) {
panic(fmt.Sprintf("unreachable: %v", h.Wait()))
})
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
-
t.Log("starting helper stub")
- if err := h.Start(ctx, true); err != nil {
+ if err := h.Start(true); err != nil {
t.Errorf("Start: error = %v", err)
cancel()
return
@@ -78,7 +77,7 @@ func testHelper(t *testing.T, createHelper func() helper.Helper) {
t.Run("start already started helper", func(t *testing.T) {
wantErr := "exec: already started"
- if err := h.Start(ctx, true); err != nil && err.Error() != wantErr {
+ if err := h.Start(true); err != nil && err.Error() != wantErr {
t.Errorf("Start: error = %v, wantErr %v",
err, wantErr)
return
@@ -107,14 +106,14 @@ func testHelper(t *testing.T, createHelper func() helper.Helper) {
})
t.Run("start helper and wait", func(t *testing.T) {
- h := createHelper()
-
- stdout, stderr := new(strings.Builder), new(strings.Builder)
- h.Stdout(stdout).Stderr(stderr)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
+ h := createHelper(ctx)
+
+ stdout, stderr := new(strings.Builder), new(strings.Builder)
+ h.SetStdout(stdout).SetStderr(stderr)
- if err := h.Start(ctx, false); err != nil {
+ if err := h.Start(false); err != nil {
t.Errorf("Start() error = %v",
err)
return