From f443d315ad60d761c06135569abb0adb183ac8c1 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sat, 15 Mar 2025 00:27:44 +0900 Subject: helper: clean up interface The helper interface was messy due to odd context acquisition order. That has changed, so this cleans it up. Signed-off-by: Ophestra --- helper/bwrap_test.go | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'helper/bwrap_test.go') diff --git a/helper/bwrap_test.go b/helper/bwrap_test.go index a14a4179..4b423564 100644 --- a/helper/bwrap_test.go +++ b/helper/bwrap_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "os" + "os/exec" "strings" "testing" "time" @@ -33,11 +34,11 @@ func TestBwrap(t *testing.T) { h := helper.MustNewBwrap( context.Background(), sc, "fortify", false, - argsWt, argF, - nil, nil, + argsWt, argF, nil, + nil, nil, false, ) - if err := h.Start(false); !errors.Is(err, os.ErrNotExist) { + if err := h.Start(); !errors.Is(err, os.ErrNotExist) { t.Errorf("Start: error = %v, wantErr %v", err, os.ErrNotExist) } @@ -47,8 +48,8 @@ func TestBwrap(t *testing.T) { if got := helper.MustNewBwrap( context.TODO(), sc, "fortify", false, - argsWt, argF, - nil, nil, + argsWt, argF, nil, + nil, nil, false, ); got == nil { t.Errorf("MustNewBwrap(%#v, %#v, %#v) got nil", sc, argsWt, "fortify") @@ -68,8 +69,8 @@ func TestBwrap(t *testing.T) { helper.MustNewBwrap( context.TODO(), &bwrap.Config{Hostname: "\x00"}, "fortify", false, - nil, argF, - nil, nil, + nil, argF, nil, + nil, nil, false, ) }) @@ -78,17 +79,14 @@ func TestBwrap(t *testing.T) { c, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() + stdout, stderr := new(strings.Builder), new(strings.Builder) h := helper.MustNewBwrap( - c, - sc, "crash-test-dummy", false, - nil, argFChecked, - nil, nil, + c, sc, "crash-test-dummy", false, + nil, argFChecked, func(cmd *exec.Cmd) { cmd.Stdout, cmd.Stderr = stdout, stderr }, + nil, nil, false, ) - stdout, stderr := new(strings.Builder), new(strings.Builder) - h.SetStdout(stdout).SetStderr(stderr) - - if err := h.Start(false); err != nil { + if err := h.Start(); err != nil { t.Errorf("Start: error = %v", err) return @@ -101,11 +99,10 @@ func TestBwrap(t *testing.T) { }) t.Run("implementation compliance", func(t *testing.T) { - testHelper(t, func(ctx context.Context) helper.Helper { + testHelper(t, func(ctx context.Context, cmdF func(cmd *exec.Cmd), stat bool) helper.Helper { return helper.MustNewBwrap( - ctx, - sc, "crash-test-dummy", false, - argsWt, argF, nil, nil, + ctx, sc, "crash-test-dummy", false, + argsWt, argF, cmdF, nil, nil, stat, ) }) }) -- cgit v1.3.1