@@ -2,58 +2,41 @@ package tools
8func TestGetSafeReadOnlyCommands(t *testing.T) {
9func TestGetSafeReadOnlyCommands(t *testing.T) {
9 commands := getSafeReadOnlyCommands()
10 commands := getSafeReadOnlyCommands()
11 // Check that we have some commands
12 // Check that we have some commands
12 if len(commands) == 0 {
13 if len(commands) == 0 {
13 t.Fatal("Expected some safe commands, got none")
14 t.Fatal("Expected some safe commands, got none")
16 // Check for cross-platform commands that should always be present
17 // Check for cross-platform commands that should always be present
17 crossPlatformCommands := []string{"echo", "hostname", "whoami", "git status", "go version"}
18 crossPlatformCommands := []string{"echo", "hostname", "whoami", "git status", "go version"}
18 for _, cmd := range crossPlatformCommands {
19 for _, cmd := range crossPlatformCommands {
19− found := false
20+ found := slices.Contains(commands, cmd)
20− for _, safeCmd := range commands {
26 if !found {
21 if !found {
27 t.Errorf("Expected cross-platform command %q to be in safe commands", cmd)
22 t.Errorf("Expected cross-platform command %q to be in safe commands", cmd)
31 if runtime.GOOS == "windows" {
26 if runtime.GOOS == "windows" {
32 // Check for Windows-specific commands
27 // Check for Windows-specific commands
33 windowsCommands := []string{"dir", "type", "Get-Process"}
28 windowsCommands := []string{"dir", "type", "Get-Process"}
34 for _, cmd := range windowsCommands {
29 for _, cmd := range windowsCommands {
35− found := false
30+ found := slices.Contains(commands, cmd)
36− for _, safeCmd := range commands {
42 if !found {
31 if !found {
43 t.Errorf("Expected Windows command %q to be in safe commands on Windows", cmd)
32 t.Errorf("Expected Windows command %q to be in safe commands on Windows", cmd)
47 // Check that Unix commands are NOT present on Windows
36 // Check that Unix commands are NOT present on Windows
48 unixCommands := []string{"ls", "pwd", "ps"}
37 unixCommands := []string{"ls", "pwd", "ps"}
49 for _, cmd := range unixCommands {
38 for _, cmd := range unixCommands {
50− found := false
39+ found := slices.Contains(commands, cmd)
51− for _, safeCmd := range commands {
57 if found {
40 if found {
58 t.Errorf("Unix command %q should not be in safe commands on Windows", cmd)
41 t.Errorf("Unix command %q should not be in safe commands on Windows", cmd)
@@ -62,28 +45,16 @@ func TestGetSafeReadOnlyCommands(t *testing.T) {
62 // Check for Unix-specific commands
45 // Check for Unix-specific commands
63 unixCommands := []string{"ls", "pwd", "ps"}
46 unixCommands := []string{"ls", "pwd", "ps"}
64 for _, cmd := range unixCommands {
47 for _, cmd := range unixCommands {
65− found := false
48+ found := slices.Contains(commands, cmd)
66− for _, safeCmd := range commands {
72 if !found {
49 if !found {
73 t.Errorf("Expected Unix command %q to be in safe commands on Unix", cmd)
50 t.Errorf("Expected Unix command %q to be in safe commands on Unix", cmd)
77 // Check that Windows-specific commands are NOT present on Unix
54 // Check that Windows-specific commands are NOT present on Unix
78 windowsOnlyCommands := []string{"dir", "Get-Process", "systeminfo"}
55 windowsOnlyCommands := []string{"dir", "Get-Process", "systeminfo"}
79 for _, cmd := range windowsOnlyCommands {
56 for _, cmd := range windowsOnlyCommands {
80− found := false
57+ found := slices.Contains(commands, cmd)
81− for _, safeCmd := range commands {
87 if found {
58 if found {
88 t.Errorf("Windows-only command %q should not be in safe commands on Unix", cmd)
59 t.Errorf("Windows-only command %q should not be in safe commands on Unix", cmd)
@@ -94,10 +65,10 @@ func TestGetSafeReadOnlyCommands(t *testing.T) {
94func TestPlatformSpecificSafeCommands(t *testing.T) {
65func TestPlatformSpecificSafeCommands(t *testing.T) {
95 // Test that the function returns different results on different platforms
66 // Test that the function returns different results on different platforms
96 commands := getSafeReadOnlyCommands()
67 commands := getSafeReadOnlyCommands()
98 hasWindowsCommands := false
69 hasWindowsCommands := false
99 hasUnixCommands := false
70 hasUnixCommands := false
101 for _, cmd := range commands {
72 for _, cmd := range commands {
102 if cmd == "dir" || cmd == "Get-Process" || cmd == "systeminfo" {
73 if cmd == "dir" || cmd == "Get-Process" || cmd == "systeminfo" {
103 hasWindowsCommands = true
74 hasWindowsCommands = true
@@ -106,7 +77,7 @@ func TestPlatformSpecificSafeCommands(t *testing.T) {
106 hasUnixCommands = true
77 hasUnixCommands = true
110 if runtime.GOOS == "windows" {
81 if runtime.GOOS == "windows" {
111 if !hasWindowsCommands {
82 if !hasWindowsCommands {
112 t.Error("Expected Windows commands on Windows platform")
83 t.Error("Expected Windows commands on Windows platform")
@@ -122,4 +93,5 @@ func TestPlatformSpecificSafeCommands(t *testing.T) {
122 t.Error("Expected Unix commands on Unix platform")
93 t.Error("Expected Unix commands on Unix platform")