@@ -14,19 +14,19 @@ func TestCommandExecutor_ExecuteCommand(t *testing.T) {
1414 ce := executor .NewCommandExecutor ()
1515
1616 tests := []struct {
17- name string
18- command string
19- cwd string
20- expectError bool
21- checkStdout bool
17+ name string
18+ command string
19+ cwd string
20+ expectError bool
21+ checkStdout bool
2222 stdoutContains string
2323 }{
2424 {
25- name : "simple echo command" ,
26- command : "echo hello" ,
27- cwd : "" ,
28- expectError : false ,
29- checkStdout : true ,
25+ name : "simple echo command" ,
26+ command : "echo hello" ,
27+ cwd : "" ,
28+ expectError : false ,
29+ checkStdout : true ,
3030 stdoutContains : "hello" ,
3131 },
3232 {
@@ -40,7 +40,7 @@ func TestCommandExecutor_ExecuteCommand(t *testing.T) {
4040 for _ , tt := range tests {
4141 t .Run (tt .name , func (t * testing.T ) {
4242 result , err := ce .ExecuteCommand (tt .command , tt .cwd )
43-
43+
4444 if (err != nil ) != tt .expectError {
4545 t .Errorf ("ExecuteCommand() error = %v, expectError %v" , err , tt .expectError )
4646 return
@@ -154,7 +154,7 @@ func TestCommandExecutor_ExecuteCommand_CommandNotFound(t *testing.T) {
154154 ce := executor .NewCommandExecutor ()
155155
156156 result , err := ce .ExecuteCommand ("nonexistentcommand12345" , "" )
157-
157+
158158 // Should return an error because command doesn't exist
159159 if err == nil && result != nil && result .ExitCode == 0 {
160160 t .Errorf ("Expected error or non-zero exit code for non-existent command" )
@@ -165,13 +165,13 @@ func TestCommandExecutor_GetInterpreter(t *testing.T) {
165165 ce := executor .NewCommandExecutor ()
166166
167167 tests := []struct {
168- name string
169- scriptPath string
168+ name string
169+ scriptPath string
170170 expectedInterpreter string
171171 }{
172172 {
173- name : "bash script with .sh extension" ,
174- scriptPath : "script.sh" ,
173+ name : "bash script with .sh extension" ,
174+ scriptPath : "script.sh" ,
175175 expectedInterpreter : func () string {
176176 if runtime .GOOS == "windows" {
177177 return "sh"
@@ -180,13 +180,13 @@ func TestCommandExecutor_GetInterpreter(t *testing.T) {
180180 }(),
181181 },
182182 {
183- name : "bash script with .bash extension" ,
184- scriptPath : "script.bash" ,
183+ name : "bash script with .bash extension" ,
184+ scriptPath : "script.bash" ,
185185 expectedInterpreter : "bash" ,
186186 },
187187 {
188- name : "PowerShell script" ,
189- scriptPath : "script.ps1" ,
188+ name : "PowerShell script" ,
189+ scriptPath : "script.ps1" ,
190190 expectedInterpreter : func () string {
191191 if runtime .GOOS == "windows" {
192192 return "powershell"
@@ -195,18 +195,18 @@ func TestCommandExecutor_GetInterpreter(t *testing.T) {
195195 }(),
196196 },
197197 {
198- name : "unsupported extension" ,
199- scriptPath : "script.py " ,
198+ name : "unsupported extension" ,
199+ scriptPath : "script.txt " ,
200200 expectedInterpreter : "" ,
201201 },
202202 {
203- name : "no extension" ,
204- scriptPath : "script" ,
203+ name : "no extension" ,
204+ scriptPath : "script" ,
205205 expectedInterpreter : "" ,
206206 },
207207 {
208- name : "uppercase extension" ,
209- scriptPath : "SCRIPT.SH" ,
208+ name : "uppercase extension" ,
209+ scriptPath : "SCRIPT.SH" ,
210210 expectedInterpreter : func () string {
211211 if runtime .GOOS == "windows" {
212212 return "sh"
@@ -238,7 +238,7 @@ func TestCommandExecutor_ExecuteScript(t *testing.T) {
238238
239239 scriptPath := filepath .Join (tmpDir , "test.sh" )
240240 scriptContent := "#!/bin/bash\n echo 'Hello from bash'\n exit 0"
241-
241+
242242 if err := os .WriteFile (scriptPath , []byte (scriptContent ), 0755 ); err != nil {
243243 t .Fatalf ("Failed to create test script: %v" , err )
244244 }
@@ -266,7 +266,7 @@ func TestCommandExecutor_ExecuteScript(t *testing.T) {
266266
267267 scriptPath := filepath .Join (tmpDir , "fail.sh" )
268268 scriptContent := "#!/bin/bash\n exit 42"
269-
269+
270270 if err := os .WriteFile (scriptPath , []byte (scriptContent ), 0755 ); err != nil {
271271 t .Fatalf ("Failed to create test script: %v" , err )
272272 }
@@ -283,9 +283,9 @@ func TestCommandExecutor_ExecuteScript(t *testing.T) {
283283 })
284284
285285 t .Run ("execute unsupported script type" , func (t * testing.T ) {
286- scriptPath := filepath .Join (tmpDir , "test.py " )
286+ scriptPath := filepath .Join (tmpDir , "test.txt " )
287287 scriptContent := "print('Hello')"
288-
288+
289289 if err := os .WriteFile (scriptPath , []byte (scriptContent ), 0755 ); err != nil {
290290 t .Fatalf ("Failed to create test script: %v" , err )
291291 }
@@ -298,7 +298,7 @@ func TestCommandExecutor_ExecuteScript(t *testing.T) {
298298
299299 t .Run ("execute non-existent script" , func (t * testing.T ) {
300300 scriptPath := filepath .Join (tmpDir , "nonexistent.sh" )
301-
301+
302302 result , err := ce .ExecuteScript (scriptPath )
303303 // Either we get an error (script doesn't exist) or non-zero exit code
304304 if err == nil && result != nil && result .ExitCode == 0 {
@@ -318,7 +318,7 @@ func TestCommandExecutor_ExecuteScript_StderrCapture(t *testing.T) {
318318
319319 scriptPath := filepath .Join (tmpDir , "stderr.sh" )
320320 scriptContent := "#!/bin/bash\n echo 'error message' >&2\n exit 1"
321-
321+
322322 if err := os .WriteFile (scriptPath , []byte (scriptContent ), 0755 ); err != nil {
323323 t .Fatalf ("Failed to create test script: %v" , err )
324324 }
@@ -395,7 +395,7 @@ func TestCommandExecutor_CommandNotFoundScenario(t *testing.T) {
395395 for _ , tt := range tests {
396396 t .Run (tt .name , func (t * testing.T ) {
397397 result , err := ce .ExecuteCommand (tt .command , "" )
398-
398+
399399 // Command not found should either return an error or non-zero exit code
400400 if err == nil && result != nil {
401401 if result .ExitCode == 0 {
@@ -421,12 +421,12 @@ func TestCommandExecutor_PermissionDeniedScenario(t *testing.T) {
421421 }
422422
423423 tmpDir := t .TempDir ()
424-
424+
425425 t .Run ("execute non-executable script" , func (t * testing.T ) {
426426 // Create a script without execute permissions
427427 scriptPath := filepath .Join (tmpDir , "no_exec.sh" )
428428 scriptContent := "#!/bin/bash\n echo 'This should not run'"
429-
429+
430430 if err := os .WriteFile (scriptPath , []byte (scriptContent ), 0644 ); err != nil {
431431 t .Fatalf ("Failed to create test script: %v" , err )
432432 }
@@ -435,12 +435,12 @@ func TestCommandExecutor_PermissionDeniedScenario(t *testing.T) {
435435 // This should fail because the file doesn't have execute permissions
436436 cmd := scriptPath
437437 result , err := ce .ExecuteCommand (cmd , "" )
438-
438+
439439 // Should fail due to permission denied
440440 if err == nil && result != nil && result .ExitCode == 0 {
441441 t .Errorf ("Expected error or non-zero exit code for non-executable script" )
442442 }
443-
443+
444444 // Note: ExecuteScript will still work because it calls bash with the script path
445445 // which doesn't require execute permissions on the script file itself
446446 })
@@ -456,7 +456,7 @@ func TestCommandExecutor_PermissionDeniedScenario(t *testing.T) {
456456 // Try to write to the read-only directory
457457 cmd := "touch " + filepath .Join (readOnlyDir , "test.txt" )
458458 result , err := ce .ExecuteCommand (cmd , "" )
459-
459+
460460 // Should fail due to permission denied
461461 if err == nil && result != nil && result .ExitCode == 0 {
462462 t .Errorf ("Expected error or non-zero exit code for writing to read-only directory" )
@@ -474,7 +474,7 @@ func TestCommandExecutor_PermissionDeniedScenario(t *testing.T) {
474474 // Try to read the protected file
475475 cmd := "cat " + protectedFile
476476 result , err := ce .ExecuteCommand (cmd , "" )
477-
477+
478478 // Should fail due to permission denied
479479 if err == nil && result != nil && result .ExitCode == 0 {
480480 t .Errorf ("Expected error or non-zero exit code for reading protected file" )
0 commit comments