aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/helper_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-13 19:50:17 +0900
committerOphestra <cat@gensokyo.uk>2025-09-13 20:01:33 +0900
commit3f25c3f0af5631dcf46584ec122f7466fb8cfe37 (patch)
tree6dbe98c080f90200c2192e416e5be319af5ae5dc /helper/helper_test.go
parente271fa77aa72d3e9b937d77a9151157b9caeadf1 (diff)
container: initialise cmd early
This allows use of more cmd methods. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper/helper_test.go')
-rw-r--r--helper/helper_test.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/helper/helper_test.go b/helper/helper_test.go
index ef4b6bca..45f7bc96 100644
--- a/helper/helper_test.go
+++ b/helper/helper_test.go
@@ -6,8 +6,10 @@ import (
"fmt"
"io"
"os"
+ "reflect"
"strconv"
"strings"
+ "syscall"
"testing"
"time"
@@ -47,6 +49,10 @@ func argFChecked(argsFd, statFd int) (args []string) {
return
}
+const (
+ containerTimeout = 30 * time.Second
+)
+
// this function tests an implementation of the helper.Helper interface
func testHelper(t *testing.T, createHelper func(ctx context.Context, setOutput func(stdoutP, stderrP *io.Writer), stat bool) helper.Helper) {
oldWaitDelay := helper.WaitDelay
@@ -54,18 +60,15 @@ func testHelper(t *testing.T, createHelper func(ctx context.Context, setOutput f
t.Cleanup(func() { helper.WaitDelay = oldWaitDelay })
t.Run("start helper with status channel and wait", func(t *testing.T) {
- ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
+ ctx, cancel := context.WithTimeout(t.Context(), containerTimeout)
stdout := new(strings.Builder)
h := createHelper(ctx, func(stdoutP, stderrP *io.Writer) { *stdoutP, *stderrP = stdout, os.Stderr }, true)
t.Run("wait not yet started helper", func(t *testing.T) {
- defer func() {
- r := recover()
- if r == nil {
- t.Fatalf("Wait did not panic")
- }
- }()
- panic(fmt.Sprintf("unreachable: %v", h.Wait()))
+ if err := h.Wait(); !reflect.DeepEqual(err, syscall.EINVAL) &&
+ !reflect.DeepEqual(err, errors.New("exec: not started")) {
+ t.Errorf("Wait: error = %v", err)
+ }
})
t.Log("starting helper stub")
@@ -108,7 +111,7 @@ func testHelper(t *testing.T, createHelper func(ctx context.Context, setOutput f
})
t.Run("start helper and wait", func(t *testing.T) {
- ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
+ ctx, cancel := context.WithTimeout(t.Context(), containerTimeout)
defer cancel()
stdout := new(strings.Builder)
h := createHelper(ctx, func(stdoutP, stderrP *io.Writer) { *stdoutP, *stderrP = stdout, os.Stderr }, false)