Adam Štrauch
37a5297c88
All checks were successful
continuous-integration/drone/push Build is passing
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
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
|
|
fakeLangDir := filepath.Join(tempDir, "techs", "python-3.10.4")
|
|
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)
|
|
}
|
|
}
|