feat: define P2 host workspace command contract
This commit is contained in:
@@ -64,3 +64,19 @@ func writeExecutable(t *testing.T, contents string) string {
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
|
||||
func TestRunnerBoundedCapturesExactlyAtLimit(t *testing.T) {
|
||||
runner := NewRunner(writeExecutable(t, "#!/bin/sh\nprintf 1234567890\nprintf error12345 >&2\n"))
|
||||
result, err := runner.RunBounded(context.Background(), nil, nil, CaptureLimits{StdoutBytes: 10, StderrBytes: 10})
|
||||
if err != nil { t.Fatal(err) }
|
||||
if result.Stdout != "1234567890" || result.Stderr != "error12345" { t.Fatalf("bounded result = %#v", result) }
|
||||
}
|
||||
|
||||
func TestRunnerBoundedRejectsOneByteOverEachStream(t *testing.T) {
|
||||
for _, script := range []string{"#!/bin/sh\nprintf 12345678901\n", "#!/bin/sh\nprintf 12345678901 >&2\n"} {
|
||||
runner := NewRunner(writeExecutable(t, script)); result, err := runner.RunBounded(context.Background(), nil, nil, CaptureLimits{StdoutBytes: 10, StderrBytes: 10})
|
||||
if !errors.Is(err, ErrOutputLimit) { t.Fatalf("err = %v result=%#v", err, result) }
|
||||
if len(result.Stdout) > 10 || len(result.Stderr) > 10 { t.Fatalf("retained overflow: %#v", result) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user