Skip to content

Commit b052d95

Browse files
refactor: streamline runtime installation checks and update test cases
- Replace direct calls to isRuntimeInstalled with Config.IsRuntimeInstalled for consistency in runtime checks - Remove the isRuntimeInstalled function to simplify the codebase - Update test cases to reflect changes in runtime installation checks
1 parent fa6b6ef commit b052d95

4 files changed

Lines changed: 8 additions & 61 deletions

File tree

cmd/init.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -279,27 +279,6 @@ func configFileTemplate(tools []tools.Tool) string {
279279
return sb.String()
280280
}
281281

282-
func processRuntime(name, version string) (*plugins.RuntimeInfo, error) {
283-
configs := []plugins.RuntimeConfig{
284-
{
285-
Name: name,
286-
Version: version,
287-
},
288-
}
289-
290-
runtimeInfos, err := plugins.ProcessRuntimes(configs, os.TempDir())
291-
if err != nil {
292-
return nil, err
293-
}
294-
295-
info, ok := runtimeInfos[name]
296-
if !ok {
297-
return nil, fmt.Errorf("runtime %s not found in processed runtimes", name)
298-
}
299-
300-
return info, nil
301-
}
302-
303282
func cliConfigFileTemplate(cliLocalMode bool) string {
304283
var cliModeString string
305284

config/runtimes-installer.go

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ func InstallRuntimes(config *ConfigType) error {
4747

4848
// InstallRuntime installs a specific runtime
4949
func InstallRuntime(name string, runtimeInfo *plugins.RuntimeInfo) error {
50-
51-
// Check if the runtime is already installed
52-
if isRuntimeInstalled(runtimeInfo) {
50+
// Skip if already installed
51+
if Config.IsRuntimeInstalled(name, runtimeInfo) {
5352
logger.Info("Runtime already installed", logrus.Fields{
5453
"runtime": name,
5554
"version": runtimeInfo.Version,
@@ -65,7 +64,7 @@ func InstallRuntime(name string, runtimeInfo *plugins.RuntimeInfo) error {
6564
}
6665

6766
// Verify that the runtime binaries are available
68-
if !isRuntimeInstalled(runtimeInfo) {
67+
if !Config.IsRuntimeInstalled(name, runtimeInfo) {
6968
logger.Error("Runtime binaries not found after extraction", logrus.Fields{
7069
"runtime": name,
7170
"version": runtimeInfo.Version,
@@ -76,37 +75,6 @@ func InstallRuntime(name string, runtimeInfo *plugins.RuntimeInfo) error {
7675
return nil
7776
}
7877

79-
// isRuntimeInstalled checks if a runtime is already installed by checking for the binary
80-
func isRuntimeInstalled(runtimeInfo *plugins.RuntimeInfo) bool {
81-
// If there are no binaries, check the install directory
82-
if len(runtimeInfo.Binaries) == 0 {
83-
_, err := os.Stat(runtimeInfo.InstallDir)
84-
if err != nil {
85-
logger.Debug("Runtime install directory not found", logrus.Fields{
86-
"directory": runtimeInfo.InstallDir,
87-
"error": err,
88-
})
89-
return false
90-
}
91-
return true
92-
}
93-
94-
// Check if at least one binary exists
95-
for binaryName, binaryPath := range runtimeInfo.Binaries {
96-
_, err := os.Stat(binaryPath)
97-
if err != nil {
98-
logger.Debug("Runtime binary not found", logrus.Fields{
99-
"binary": binaryName,
100-
"path": binaryPath,
101-
"error": err,
102-
})
103-
return false
104-
}
105-
}
106-
107-
return true
108-
}
109-
11078
// downloadAndExtractRuntime downloads and extracts a runtime
11179
func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
11280
// Create a file name for the downloaded archive

config/runtimes-installer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func TestIsRuntimeInstalled(t *testing.T) {
2424
}
2525

2626
// Test when the install directory doesn't exist
27-
assert.False(t, isRuntimeInstalled(runtimeInfoNoBinaries))
27+
assert.False(t, Config.IsRuntimeInstalled("test-runtime", runtimeInfoNoBinaries))
2828

2929
// Create the install directory
3030
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, utils.DefaultDirPerms)
3131
assert.NoError(t, err)
3232

3333
// Test when the install directory exists
34-
assert.True(t, isRuntimeInstalled(runtimeInfoNoBinaries))
34+
assert.True(t, Config.IsRuntimeInstalled("test-runtime", runtimeInfoNoBinaries))
3535

3636
// Create a mock RuntimeInfo with binaries
3737
binPath := filepath.Join(tempDir, "test-runtime-bin")
@@ -45,12 +45,12 @@ func TestIsRuntimeInstalled(t *testing.T) {
4545
}
4646

4747
// Test when the binary doesn't exist
48-
assert.False(t, isRuntimeInstalled(runtimeInfoWithBinaries))
48+
assert.False(t, Config.IsRuntimeInstalled("test-runtime", runtimeInfoWithBinaries))
4949

5050
// Create a mock binary file
5151
_, err = os.Create(binPath)
5252
assert.NoError(t, err)
5353

5454
// Test when the binary exists
55-
assert.True(t, isRuntimeInstalled(runtimeInfoWithBinaries))
55+
assert.True(t, Config.IsRuntimeInstalled("test-runtime", runtimeInfoWithBinaries))
5656
}

config/tools-installer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func InstallTools(config *ConfigType, registry string) error {
5858
// InstallTool installs a specific tool
5959
func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error {
6060
// Check if the tool is already installed
61-
if isToolInstalled(toolInfo) {
61+
if Config.IsToolInstalled(name, toolInfo) {
6262
logger.Info("Tool already installed", logrus.Fields{
6363
"tool": name,
6464
"version": toolInfo.Version,

0 commit comments

Comments
 (0)