(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func TestLocalSandbox_Exec(t *testing.T) { |
| 38 | tmpDir, err := os.MkdirTemp("", "sandbox-test-*") |
| 39 | if err != nil { |
| 40 | t.Fatalf("failed to create temp dir: %v", err) |
| 41 | } |
| 42 | defer func() { _ = os.RemoveAll(tmpDir) }() |
| 43 | |
| 44 | sb, err := NewLocalSandbox(&LocalSandboxConfig{ |
| 45 | WorkDir: tmpDir, |
| 46 | }) |
| 47 | if err != nil { |
| 48 | t.Fatalf("failed to create sandbox: %v", err) |
| 49 | } |
| 50 | defer func() { _ = sb.Dispose() }() |
| 51 | |
| 52 | ctx := context.Background() |
| 53 | |
| 54 | // Test simple command |
| 55 | result, err := sb.Exec(ctx, "echo hello", nil) |
| 56 | if err != nil { |
| 57 | t.Fatalf("exec failed: %v", err) |
| 58 | } |
| 59 | if result.Code != 0 { |
| 60 | t.Errorf("expected exit code 0, got %d", result.Code) |
| 61 | } |
| 62 | if result.Stdout != "hello\n" { |
| 63 | t.Errorf("expected stdout='hello\\n', got '%s'", result.Stdout) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func TestLocalSandbox_DangerousCommand(t *testing.T) { |
| 68 | tmpDir, err := os.MkdirTemp("", "sandbox-test-*") |
nothing calls this directly
no test coverage detected