Skip to content

Commit 128eb98

Browse files
committed
Refactor createCommandWithEnhancedPath to improve PATH handling and update TestVerifyEnginePath to skip on non-Windows systems
1 parent 2dbf5b4 commit 128eb98

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

internal/services/realtimeengine/iacrealtime/container-manager.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ func createCommandWithEnhancedPath(enginePath string, args ...string) *exec.Cmd
7777
// Build enhanced PATH (prepend additional paths to ensure they take priority)
7878
var enhancedPathParts []string
7979
for _, p := range additionalPaths {
80-
// Only add if not already in PATH and directory exists
81-
if !pathSet[p] {
82-
if _, err := os.Stat(p); err == nil {
83-
enhancedPathParts = append(enhancedPathParts, p)
84-
}
80+
// Skip if already in PATH
81+
if pathSet[p] {
82+
continue
83+
}
84+
// Only add if directory exists
85+
if _, err := os.Stat(p); err == nil {
86+
enhancedPathParts = append(enhancedPathParts, p)
8587
}
8688
}
8789
enhancedPathParts = append(enhancedPathParts, currentPath)

internal/services/realtimeengine/iacrealtime/iac-realtime_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,14 +1187,16 @@ func TestVerifyEnginePath_DirectoryInsteadOfFile(t *testing.T) {
11871187
}
11881188

11891189
func TestVerifyEnginePath_ValidSystemExecutable(t *testing.T) {
1190-
// Test with a known system executable
1191-
var execPath string
1192-
if runtime.GOOS == osWindows {
1193-
execPath = "C:\\Windows\\System32\\cmd.exe"
1194-
} else {
1195-
execPath = "/bin/sh"
1190+
// This test only runs on Windows because:
1191+
// - On Linux, common executables like /bin/sh don't properly support --version flag
1192+
// - The verifyEnginePath function is designed for Docker/Podman which do support --version
1193+
// - We have other tests covering the main code paths (directory check, file existence, etc.)
1194+
if runtime.GOOS != osWindows {
1195+
t.Skip("Skipping on non-Windows: system executables may not support --version flag")
11961196
}
11971197

1198+
execPath := "C:\\Windows\\System32\\cmd.exe"
1199+
11981200
// Check if the executable exists first
11991201
if _, err := os.Stat(execPath); err != nil {
12001202
t.Skipf("System executable not found: %s", execPath)

0 commit comments

Comments
 (0)