test(commands): add coverage for AddPath init flag

This commit is contained in:
Marc 2024-01-31 20:05:27 -05:00
parent 906cf9a4b0
commit 037409a460
Signed by: marc
GPG key ID: 048E042F22B5DC79

View file

@ -1,11 +1,13 @@
package main
import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
cli "v/cli"
logger "v/logger"
python "v/python"
state "v/state"
testutils "v/testutils"
@ -79,3 +81,26 @@ func TestInitializeCreatesAllPythonShims(t *testing.T) {
}
}
}
func TestInitializeWithAddPathPrintsExportPATH(t *testing.T) {
defer testutils.SetupAndCleanupEnvironment(t)()
var buf bytes.Buffer
logger.InfoLogger.SetOutput(&buf)
defer func() {
logger.InfoLogger.SetOutput(os.Stdout)
}()
err := Initialize([]string{}, cli.Flags{AddPath: true}, state.State{})
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
expected := "export PATH=" + state.GetStatePath("shims") + ":$PATH\n"
if buf.String() != expected {
t.Errorf("Expected PATH export, got %s", buf.String())
}
}