Skip to content

Commit 22ac331

Browse files
committed
Fix jetbrains tests for windows
1 parent 1a264de commit 22ac331

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

artifactory/commands/ide/jetbrains/jetbrains.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,21 @@ func (jc *JetbrainsCommand) detectJetBrainsIDEs() error {
160160

161161
switch runtime.GOOS {
162162
case "darwin":
163-
configBasePath = filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "JetBrains")
163+
// Check for test override first, then use standard HOME location
164+
testHome := os.Getenv("TEST_HOME")
165+
if testHome != "" {
166+
configBasePath = filepath.Join(testHome, "Library", "Application Support", "JetBrains")
167+
} else {
168+
configBasePath = filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "JetBrains")
169+
}
164170
case "windows":
165-
configBasePath = filepath.Join(os.Getenv("APPDATA"), "JetBrains")
171+
// Check for test override first, then use standard APPDATA location
172+
testAppData := os.Getenv("TEST_APPDATA")
173+
if testAppData != "" {
174+
configBasePath = filepath.Join(testAppData, "JetBrains")
175+
} else {
176+
configBasePath = filepath.Join(os.Getenv("APPDATA"), "JetBrains")
177+
}
166178
case "linux":
167179
// Respect XDG_CONFIG_HOME environment variable
168180
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")

artifactory/commands/ide/jetbrains/jetbrains_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,52 @@ func BenchmarkJetbrainsCommand_ParseIDEFromDirName(b *testing.B) {
460460
}
461461
}
462462
}
463+
464+
func TestJetbrainsCommand_DetectJetBrainsIDEs_WithTestAppData(t *testing.T) {
465+
// Test TEST_APPDATA support for Windows testing environments
466+
467+
// Create temporary directory for TEST_APPDATA
468+
tempDir := t.TempDir()
469+
470+
// Create mock JetBrains configuration directory structure
471+
jetbrainsDir := filepath.Join(tempDir, "JetBrains")
472+
ideaDir := filepath.Join(jetbrainsDir, "IntelliJIdea2023.3")
473+
err := os.MkdirAll(ideaDir, 0755)
474+
require.NoError(t, err)
475+
476+
// Create mock idea.properties file
477+
propertiesPath := filepath.Join(ideaDir, "idea.properties")
478+
propertiesContent := "# Test properties\nide.system.path=${user.home}/.local/share/JetBrains/IntelliJIdea2023.3\n"
479+
err = os.WriteFile(propertiesPath, []byte(propertiesContent), 0644)
480+
require.NoError(t, err)
481+
482+
// Set TEST_APPDATA environment variable
483+
originalTestAppData := os.Getenv("TEST_APPDATA")
484+
defer func() {
485+
if originalTestAppData != "" {
486+
_ = os.Setenv("TEST_APPDATA", originalTestAppData)
487+
} else {
488+
_ = os.Unsetenv("TEST_APPDATA")
489+
}
490+
}()
491+
err = os.Setenv("TEST_APPDATA", tempDir)
492+
require.NoError(t, err)
493+
494+
// Create JetBrains command and test detection
495+
cmd := &JetbrainsCommand{}
496+
497+
// For testing, temporarily modify runtime.GOOS to simulate Windows behavior
498+
// Note: We can't actually change runtime.GOOS, so this test documents the intended behavior
499+
if runtime.GOOS == "windows" {
500+
// Run detection - should find our mock IDE
501+
err = cmd.detectJetBrainsIDEs()
502+
// Should succeed when TEST_APPDATA points to our mock directory
503+
require.NoError(t, err)
504+
require.Len(t, cmd.detectedIDEs, 1)
505+
require.Equal(t, "IntelliJ IDEA", cmd.detectedIDEs[0].Name)
506+
require.Equal(t, "2023.3", cmd.detectedIDEs[0].Version)
507+
} else {
508+
// On non-Windows, TEST_APPDATA should not affect detection
509+
t.Logf("TEST_APPDATA test is primarily for Windows environments")
510+
}
511+
}

0 commit comments

Comments
 (0)