Skip to content

Commit 3ebfa38

Browse files
committed
fixed test modules and files
1 parent 6cb8193 commit 3ebfa38

4 files changed

Lines changed: 64 additions & 60 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/charmbracelet/bubbletea v1.3.10
88
github.com/charmbracelet/lipgloss v1.1.0
99
github.com/leanovate/gopter v0.2.11
10+
pgregory.net/rapid v1.2.0
1011
)
1112

1213
require (
@@ -27,5 +28,4 @@ require (
2728
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
2829
golang.org/x/sys v0.36.0 // indirect
2930
golang.org/x/text v0.8.0 // indirect
30-
pgregory.net/rapid v1.2.0 // indirect
3131
)

internal/installer/installer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func TestGetGoInstallCommand(t *testing.T) {
5050
t.Errorf("Unexpected command: %s", command)
5151
}
5252
case "linux":
53-
if packageManager != "manual" {
54-
t.Errorf("Expected manual on Linux, got %s", packageManager)
53+
if packageManager != "direct" {
54+
t.Errorf("Expected direct on Linux, got %s", packageManager)
5555
}
5656
default:
5757
t.Logf("Unknown OS: %s", runtime.GOOS)

tests/property/command_execution_properties_test.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
170170
func(filename string) bool {
171171
ce := executor.NewCommandExecutor()
172172
scriptPath := filename + ".sh"
173-
173+
174174
interpreter := ce.GetInterpreter(scriptPath)
175-
175+
176176
// On Windows, .sh files should use "sh"
177177
// On Unix systems, .sh files should use "bash"
178178
if runtime.GOOS == "windows" {
@@ -187,9 +187,9 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
187187
func(filename string) bool {
188188
ce := executor.NewCommandExecutor()
189189
scriptPath := filename + ".bash"
190-
190+
191191
interpreter := ce.GetInterpreter(scriptPath)
192-
192+
193193
return interpreter == "bash"
194194
},
195195
gen.Identifier(),
@@ -199,9 +199,9 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
199199
func(filename string) bool {
200200
ce := executor.NewCommandExecutor()
201201
scriptPath := filename + ".ps1"
202-
202+
203203
interpreter := ce.GetInterpreter(scriptPath)
204-
204+
205205
// On Windows, .ps1 files should use "powershell"
206206
// On Unix systems, .ps1 files should use "pwsh" (PowerShell Core)
207207
if runtime.GOOS == "windows" {
@@ -215,22 +215,22 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
215215
properties.Property("unsupported extensions return empty string", prop.ForAll(
216216
func(filename string, ext string) bool {
217217
ce := executor.NewCommandExecutor()
218-
219-
// Use extensions that are not .sh, .bash, or .ps1
218+
219+
// Use extensions that are not supported script runners
220220
scriptPath := filename + "." + ext
221-
221+
222222
interpreter := ce.GetInterpreter(scriptPath)
223-
223+
224224
return interpreter == ""
225225
},
226226
gen.Identifier(),
227-
gen.OneConstOf("txt", "py", "js", "go", "md", "json", "xml"),
227+
gen.OneConstOf("txt", "js", "md", "json", "xml", "html"),
228228
))
229229

230230
properties.Property("case insensitive extension matching", prop.ForAll(
231231
func(filename string, caseVariant int) bool {
232232
ce := executor.NewCommandExecutor()
233-
233+
234234
// Test different case variants of .sh extension
235235
var scriptPath string
236236
switch caseVariant % 4 {
@@ -243,9 +243,9 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
243243
case 3:
244244
scriptPath = filename + ".sH"
245245
}
246-
246+
247247
interpreter := ce.GetInterpreter(scriptPath)
248-
248+
249249
// Should still recognize the extension regardless of case
250250
if runtime.GOOS == "windows" {
251251
return interpreter == "sh"
@@ -259,12 +259,12 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
259259
properties.Property("paths with directories handled correctly", prop.ForAll(
260260
func(dir string, filename string, ext string) bool {
261261
ce := executor.NewCommandExecutor()
262-
262+
263263
// Create a path with directory components
264264
scriptPath := dir + "/" + filename + ext
265-
265+
266266
interpreter := ce.GetInterpreter(scriptPath)
267-
267+
268268
// Verify interpreter is selected based on extension, not path
269269
switch ext {
270270
case ".sh":
@@ -279,13 +279,17 @@ func TestProperty_ScriptInterpreterSelection(t *testing.T) {
279279
return interpreter == "powershell"
280280
}
281281
return interpreter == "pwsh"
282+
case ".py":
283+
return interpreter == "python3"
284+
case ".go":
285+
return interpreter == "go"
282286
default:
283287
return interpreter == ""
284288
}
285289
},
286290
gen.Identifier(),
287291
gen.Identifier(),
288-
gen.OneConstOf(".sh", ".bash", ".ps1", ".txt", ".py"),
292+
gen.OneConstOf(".sh", ".bash", ".ps1", ".txt", ".py", ".go"),
289293
))
290294

291295
properties.TestingRun(t, gopter.ConsoleReporter(false))

tests/unit/commandexecutor_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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\necho 'Hello from bash'\nexit 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\nexit 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\necho 'error message' >&2\nexit 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\necho '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

Comments
 (0)