|
6 | 6 | "strings" |
7 | 7 | "testing" |
8 | 8 |
|
| 9 | + "github.com/version-fox/vfox/internal/config" |
9 | 10 | "github.com/version-fox/vfox/internal/env" |
10 | 11 | "github.com/version-fox/vfox/internal/pathmeta" |
11 | 12 | ) |
@@ -510,6 +511,61 @@ func TestEnsureVfoxInGitignore(t *testing.T) { |
510 | 511 | } |
511 | 512 | } |
512 | 513 |
|
| 514 | +func TestNewSdk_PrefersPrimaryInstallPath(t *testing.T) { |
| 515 | + tempDir := t.TempDir() |
| 516 | + installRoot := filepath.Join(tempDir, "sdks") |
| 517 | + pluginPath := filepath.Join("..", "plugin", "testdata", "plugins", "java_with_metadata") |
| 518 | + |
| 519 | + primaryInstallPath := filepath.Join(installRoot, "java_with_metadata") |
| 520 | + legacyInstallPath := filepath.Join(installRoot, "cache", "java_with_metadata") |
| 521 | + |
| 522 | + if err := os.MkdirAll(primaryInstallPath, 0755); err != nil { |
| 523 | + t.Fatalf("Failed to create primary install path: %v", err) |
| 524 | + } |
| 525 | + if err := os.MkdirAll(legacyInstallPath, 0755); err != nil { |
| 526 | + t.Fatalf("Failed to create legacy install path: %v", err) |
| 527 | + } |
| 528 | + |
| 529 | + source, err := NewSdk(&env.RuntimeEnvContext{ |
| 530 | + UserConfig: config.DefaultConfig, |
| 531 | + PathMeta: &pathmeta.PathMeta{Shared: pathmeta.SharedPaths{Installs: installRoot}}, |
| 532 | + RuntimeVersion: "test", |
| 533 | + }, pluginPath) |
| 534 | + if err != nil { |
| 535 | + t.Fatalf("NewSdk returned error: %v", err) |
| 536 | + } |
| 537 | + defer source.Close() |
| 538 | + |
| 539 | + if got := source.Metadata().SdkInstalledPath; got != primaryInstallPath { |
| 540 | + t.Fatalf("SdkInstalledPath = %q, want %q", got, primaryInstallPath) |
| 541 | + } |
| 542 | +} |
| 543 | + |
| 544 | +func TestNewSdk_FallsBackToLegacyInstallPath(t *testing.T) { |
| 545 | + tempDir := t.TempDir() |
| 546 | + installRoot := filepath.Join(tempDir, "sdks") |
| 547 | + pluginPath := filepath.Join("..", "plugin", "testdata", "plugins", "java_with_metadata") |
| 548 | + |
| 549 | + legacyInstallPath := filepath.Join(installRoot, "cache", "java_with_metadata") |
| 550 | + if err := os.MkdirAll(legacyInstallPath, 0755); err != nil { |
| 551 | + t.Fatalf("Failed to create legacy install path: %v", err) |
| 552 | + } |
| 553 | + |
| 554 | + source, err := NewSdk(&env.RuntimeEnvContext{ |
| 555 | + UserConfig: config.DefaultConfig, |
| 556 | + PathMeta: &pathmeta.PathMeta{Shared: pathmeta.SharedPaths{Installs: installRoot}}, |
| 557 | + RuntimeVersion: "test", |
| 558 | + }, pluginPath) |
| 559 | + if err != nil { |
| 560 | + t.Fatalf("NewSdk returned error: %v", err) |
| 561 | + } |
| 562 | + defer source.Close() |
| 563 | + |
| 564 | + if got := source.Metadata().SdkInstalledPath; got != legacyInstallPath { |
| 565 | + t.Fatalf("SdkInstalledPath = %q, want %q", got, legacyInstallPath) |
| 566 | + } |
| 567 | +} |
| 568 | + |
513 | 569 | // Helper function to check if a line exists in content |
514 | 570 | func containsLine(content, line string) bool { |
515 | 571 | lines := splitLines(content) |
|
0 commit comments