Skip to content

Commit 5757dca

Browse files
WINBLOWS
1 parent 27a0628 commit 5757dca

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

cmd/diagnostics/doctor_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,15 @@ func TestCheckSystemGoVersion(t *testing.T) {
14371437

14381438
for _, tt := range tests {
14391439
t.Run(tt.name, func(t *testing.T) {
1440+
// On Windows, find the real Go compiler BEFORE any environment setup
1441+
// This is needed to compile mock executables later
1442+
var realGoPath string
1443+
if utils.IsWindows() && tt.hasSystemGo {
1444+
var err error
1445+
realGoPath, err = exec.LookPath("go")
1446+
require.NoError(t, err, "Failed to find Go compiler in PATH before test setup")
1447+
}
1448+
14401449
// Use cmdtest for proper environment isolation
14411450
testRoot, cleanup := cmdtest.SetupTestEnv(t)
14421451
defer cleanup()
@@ -1469,11 +1478,6 @@ func TestCheckSystemGoVersion(t *testing.T) {
14691478
// On Windows, create a real compiled executable to avoid exec.Command issues with .bat files
14701479
goBinary += ".exe"
14711480

1472-
// Find the real Go compiler before modifying PATH
1473-
// This ensures we can compile even if PATH gets modified
1474-
realGoPath, err := exec.LookPath("go")
1475-
require.NoError(t, err, "Failed to find Go compiler in PATH")
1476-
14771481
// Create a temporary Go source file
14781482
sourceFile := filepath.Join(systemGoDir, "go.go")
14791483
sourceCode := `package main
@@ -1485,7 +1489,7 @@ func main() {
14851489
err = os.WriteFile(sourceFile, []byte(sourceCode), 0o644)
14861490
require.NoError(t, err)
14871491

1488-
// Compile it to create the executable using absolute path to real Go
1492+
// Compile it to create the executable using the saved real Go path
14891493
cmd := exec.Command(realGoPath, "build", "-o", goBinary, sourceFile)
14901494
output, err := cmd.CombinedOutput()
14911495
require.NoError(t, err, "Failed to compile mock go.exe: %s", output)

0 commit comments

Comments
 (0)