helper: test child process handling

The stub child process simulates reading from the argument fd and copies the entire payload unmodified to stdout. If status pipe is enabled it will simulate sync fd behaviour as well.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-09-29 14:59:39 +09:00
parent 61ba841c88
commit 3bf456da65
2 changed files with 211 additions and 0 deletions

29
helper/args_test.go Normal file
View File

@@ -0,0 +1,29 @@
package helper_test
import (
"errors"
"fmt"
"strings"
"testing"
"git.ophivana.moe/cat/fortify/helper"
)
func Test_argsFD_String(t *testing.T) {
argsOnce.Do(prepareArgs)
wantString := strings.Join(want, " ")
if got := argsWt.(fmt.Stringer).String(); got != wantString {
t.Errorf("String(): got %v; want %v",
got, wantString)
}
}
func TestNewCheckedArgs(t *testing.T) {
args := []string{"\x00"}
if _, err := helper.NewCheckedArgs(args); !errors.Is(err, helper.ErrContainsNull) {
t.Errorf("NewCheckedArgs(%q) error = %v, wantErr %v",
args,
err, helper.ErrContainsNull)
}
}