Change MINIKUBE_HOME logic

pull/18648/head
Tony-Sol 2024-04-15 22:46:01 +03:00
parent ca9cc89671
commit 6f036752c2
No known key found for this signature in database
3 changed files with 14 additions and 10 deletions

View File

@ -456,7 +456,7 @@ func TestUpdateIP(t *testing.T) {
},
}
t.Setenv(localpath.MinikubeHome, "/home/la-croix")
t.Setenv(localpath.MinikubeHome, "/home/la-croix/.minikube")
for _, test := range tests {
test := test
@ -492,7 +492,7 @@ func TestUpdateIP(t *testing.T) {
}
func TestMissingContext(t *testing.T) {
t.Setenv(localpath.MinikubeHome, "/home/la-croix")
t.Setenv(localpath.MinikubeHome, "/home/la-croix/.minikube")
configFilename := tempFile(t, kubeConfigMissingContext)
defer os.Remove(configFilename)
if _, err := UpdateEndpoint("minikube", "192.168.10.100", 8080, configFilename, nil); err != nil {

View File

@ -47,7 +47,12 @@ func MiniPath() string {
if filepath.Base(minikubeHomeEnv) == ".minikube" {
return minikubeHomeEnv
}
return filepath.Join(minikubeHomeEnv, ".minikube")
legacyMinikubeHome := filepath.Join(minikubeHomeEnv, ".minikube")
if _, err := os.Stat(legacyMinikubeHome); !os.IsNotExist(err) {
return legacyMinikubeHome
}
return filepath.Clean(minikubeHomeEnv)
}
// MakeMiniPath is a utility to calculate a relative path to our directory.

View File

@ -63,19 +63,18 @@ func TestHasWindowsDriveLetter(t *testing.T) {
func TestMiniPath(t *testing.T) {
var testCases = []struct {
env, basePath string
env, expectedPath string
}{
{"/tmp/.minikube", "/tmp/"},
{"/tmp/", "/tmp"},
{"", homedir.HomeDir()},
{"/tmp/.minikube", "/tmp/.minikube"},
{"/tmp", "/tmp"},
{"", filepath.Join(homedir.HomeDir(), ".minikube")},
}
for _, tc := range testCases {
t.Run(tc.env, func(t *testing.T) {
expectedPath := filepath.Join(tc.basePath, ".minikube")
t.Setenv(MinikubeHome, tc.env)
path := MiniPath()
if path != expectedPath {
t.Errorf("MiniPath expected to return '%s', but got '%s'", expectedPath, path)
if path != tc.expectedPath {
t.Errorf("MiniPath expected to return '%s', but got '%s'", tc.expectedPath, path)
}
})
}