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/cmd_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/cmd_test.go')
| -rw-r--r-- | helper/cmd_test.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/helper/cmd_test.go b/helper/cmd_test.go index 60c0caff..9c640983 100644 --- a/helper/cmd_test.go +++ b/helper/cmd_test.go @@ -3,6 +3,7 @@ package helper_test import ( "context" "errors" + "io" "os" "os/exec" "testing" @@ -10,9 +11,9 @@ import ( "git.gensokyo.uk/security/fortify/helper" ) -func TestDirect(t *testing.T) { +func TestCmd(t *testing.T) { t.Run("start non-existent helper path", func(t *testing.T) { - h := helper.NewDirect(context.Background(), "/nonexistent", argsWt, false, argF, nil, nil) + h := helper.NewDirect(context.Background(), "/proc/nonexistent", argsWt, false, argF, nil, nil) if err := h.Start(); !errors.Is(err, os.ErrNotExist) { t.Errorf("Start: error = %v, wantErr %v", @@ -22,15 +23,17 @@ func TestDirect(t *testing.T) { t.Run("valid new helper nil check", func(t *testing.T) { if got := helper.NewDirect(context.TODO(), "fortify", argsWt, false, argF, nil, nil); got == nil { - t.Errorf("New(%q, %q) got nil", + t.Errorf("NewDirect(%q, %q) got nil", argsWt, "fortify") return } }) t.Run("implementation compliance", func(t *testing.T) { - testHelper(t, func(ctx context.Context, cmdF func(cmd *exec.Cmd), stat bool) helper.Helper { - return helper.NewDirect(ctx, "crash-test-dummy", argsWt, stat, argF, cmdF, nil) - }) + testHelper(t, func(ctx context.Context, setOutput func(stdoutP, stderrP *io.Writer), stat bool) helper.Helper { + return helper.NewDirect(ctx, os.Args[0], argsWt, stat, argF, func(cmd *exec.Cmd) { + setOutput(&cmd.Stdout, &cmd.Stderr) + }, nil) + }, "exec") }) } |
