Files
clawgo/pkg/tools/shell_test.go
2026-02-19 21:53:38 +08:00

37 lines
863 B
Go

package tools
import (
"context"
"strings"
"testing"
"time"
"clawgo/pkg/config"
)
func TestExecToolExecuteBasicCommand(t *testing.T) {
tool := NewExecTool(config.ShellConfig{Timeout: 2 * time.Second}, ".")
out, err := tool.Execute(context.Background(), map[string]interface{}{
"command": "echo hello",
})
if err != nil {
t.Fatalf("execute failed: %v", err)
}
if !strings.Contains(out, "hello") {
t.Fatalf("expected output to contain hello, got %q", out)
}
}
func TestExecToolExecuteTimeout(t *testing.T) {
tool := NewExecTool(config.ShellConfig{Timeout: 20 * time.Millisecond}, ".")
out, err := tool.Execute(context.Background(), map[string]interface{}{
"command": "sleep 1",
})
if err != nil {
t.Fatalf("execute failed: %v", err)
}
if !strings.Contains(out, "timed out") {
t.Fatalf("expected timeout message, got %q", out)
}
}