aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper
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
parente271fa77aa72d3e9b937d77a9151157b9caeadf1 (diff)
container: initialise cmd early
This allows use of more cmd methods. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper')
-rw-r--r--helper/container_test.go4
-rw-r--r--helper/helper_test.go21
2 files changed, 14 insertions, 11 deletions
diff --git a/helper/container_test.go b/helper/container_test.go
index 2d1c256c..9aaeec8e 100644
--- a/helper/container_test.go
+++ b/helper/container_test.go
@@ -11,10 +11,10 @@ import (
)
func TestContainer(t *testing.T) {
- t.Run("start empty container", func(t *testing.T) {
+ t.Run("start invalid container", func(t *testing.T) {
h := helper.New(t.Context(), container.MustAbs(container.Nonexistent), "hakurei", argsWt, false, argF, nil, nil)
- wantErr := "container: starting an empty container"
+ wantErr := "container: starting an invalid container"
if err := h.Start(); err == nil || err.Error() != wantErr {
t.Errorf("Start: error = %v, wantErr %q",
err, wantErr)
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)