43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCallRejectsEmptyCommand(t *testing.T) {
|
|
tool := New([]string{"echo"}, ".", time.Second, 4000, nil)
|
|
_, err := tool.Call(context.Background(), " ")
|
|
if err == nil {
|
|
t.Fatal("expected error for empty command")
|
|
}
|
|
}
|
|
|
|
func TestCallAllowsNonAllowlistedCommand(t *testing.T) {
|
|
tool := New([]string{"echo"}, ".", time.Second, 4000, nil)
|
|
out, err := tool.Call(context.Background(), "go version")
|
|
if err != nil {
|
|
t.Fatalf("expected command to run without allowlist restriction, got err=%v", err)
|
|
}
|
|
if out == "" {
|
|
t.Fatal("expected non-empty output")
|
|
}
|
|
}
|
|
|
|
func TestCallWindowsDateIsNonInteractive(t *testing.T) {
|
|
if runtime.GOOS != "windows" {
|
|
t.Skip("windows-only test")
|
|
}
|
|
tool := New(nil, ".", 3*time.Second, 4000, nil)
|
|
out, err := tool.Call(context.Background(), "date")
|
|
if err != nil {
|
|
t.Fatalf("expected bare date command to succeed on windows, got err=%v output=%q", err, out)
|
|
}
|
|
if strings.TrimSpace(out) == "" {
|
|
t.Fatal("expected non-empty output for date command")
|
|
}
|
|
}
|