test(commands): add shim creation coverage
This commit is contained in:
parent
2b7b63c9b4
commit
a11fe69f65
1 changed files with 52 additions and 0 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
cli "v/cli"
|
||||
python "v/python"
|
||||
state "v/state"
|
||||
testutils "v/testutils"
|
||||
)
|
||||
|
@ -27,3 +29,53 @@ func TestWriteShim(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func TestInitializeCreatesStateDirectories(t *testing.T) {
|
||||
defer testutils.SetupAndCleanupEnvironment(t)()
|
||||
|
||||
err := Initialize([]string{}, cli.Flags{}, state.State{})
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error initializing")
|
||||
}
|
||||
|
||||
if _, err = os.Stat(state.GetStatePath()); os.IsNotExist(err) {
|
||||
t.Errorf("Root state directory not found")
|
||||
}
|
||||
|
||||
if _, err = os.Stat(state.GetStatePath("shims")); os.IsNotExist(err) {
|
||||
t.Errorf("Shims directory not found")
|
||||
}
|
||||
|
||||
if _, err = os.Stat(state.GetStatePath("cache")); os.IsNotExist(err) {
|
||||
t.Errorf("Cache directory not found")
|
||||
}
|
||||
|
||||
if _, err = os.Stat(state.GetStatePath("runtimes")); os.IsNotExist(err) {
|
||||
t.Errorf("Runtimes directory not found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitializeCreatesAllPythonShims(t *testing.T) {
|
||||
defer testutils.SetupAndCleanupEnvironment(t)()
|
||||
|
||||
err := Initialize([]string{}, cli.Flags{}, state.State{})
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error initializing")
|
||||
}
|
||||
|
||||
expectedShims := python.Shims
|
||||
|
||||
for shimLabel, shimCall := range expectedShims {
|
||||
shimContent, err := os.ReadFile(state.GetStatePath("shims", shimLabel))
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
t.Errorf("%s shim not created", shimLabel)
|
||||
}
|
||||
|
||||
if !strings.Contains(string(shimContent), shimCall) {
|
||||
t.Errorf("%s shim does not contain expected call (%s not in %s)", shimLabel, shimCall, shimContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue