2023-04-24 12:19:58 +00:00
|
|
|
package containers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetTechAndVersion(t *testing.T) {
|
|
|
|
// Create a temporary directory for testing
|
|
|
|
tempDir := t.TempDir()
|
|
|
|
|
|
|
|
// Create a fake language directory with version in the temporary directory
|
2023-04-24 20:35:58 +00:00
|
|
|
fakeLangDir := filepath.Join(tempDir, "techs", "python-3.10.4", "bin")
|
2023-04-24 12:19:58 +00:00
|
|
|
err := os.MkdirAll(fakeLangDir, 0755)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create fake language directory: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a symlink for testing
|
|
|
|
symlink := filepath.Join(tempDir, "primary_tech")
|
|
|
|
err = os.Symlink(fakeLangDir, symlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create symlink: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test parseLanguageAndVersion function
|
|
|
|
info, err := getTechAndVersion(symlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedLanguage := "python"
|
|
|
|
expectedVersion := "3.10.4"
|
|
|
|
if info.Tech != expectedLanguage || info.Version != expectedVersion {
|
|
|
|
t.Errorf("Expected language: %s, version: %s, but got language: %s, version: %s",
|
|
|
|
expectedLanguage, expectedVersion, info.Tech, info.Version)
|
|
|
|
}
|
|
|
|
}
|