From f1fd357ce74bbb7789445ed8c1946a411c02a66c Mon Sep 17 00:00:00 2001 From: Bob Sira Date: Wed, 5 Nov 2025 02:13:20 +0000 Subject: [PATCH] fixed TestGetKubeConfigPath unit test windows --- pkg/minikube/kubeconfig/kubeconfig_test.go | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/kubeconfig/kubeconfig_test.go b/pkg/minikube/kubeconfig/kubeconfig_test.go index eedc08239141..bd5bb50dc407 100644 --- a/pkg/minikube/kubeconfig/kubeconfig_test.go +++ b/pkg/minikube/kubeconfig/kubeconfig_test.go @@ -767,7 +767,20 @@ func contextEquals(aContext, bContext *api.Context) bool { return true } +func equalPaths(a, b string) bool { + return filepath.Clean(filepath.ToSlash(a)) == filepath.Clean(filepath.ToSlash(b)) +} + func TestGetKubeConfigPath(t *testing.T) { + sep := string(os.PathListSeparator) + + // Ensure $HOME expands sensibly on Windows where HOME may be unset. + if os.Getenv("HOME") == "" { + if up := os.Getenv("USERPROFILE"); up != "" { + _ = os.Setenv("HOME", up) + } + } + var tests = []struct { input string want string @@ -777,15 +790,17 @@ func TestGetKubeConfigPath(t *testing.T) { want: "/home/fake/.kube/.kubeconfig", }, { - input: "/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig", + // multiple entries, first should be chosen + input: "/home/fake/.kube/.kubeconfig" + sep + "/home/fake2/.kubeconfig", want: "/home/fake/.kube/.kubeconfig", }, { - input: ":/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig", + // leading empty entry should be skipped + input: sep + "/home/fake/.kube/.kubeconfig" + sep + "/home/fake2/.kubeconfig", want: "/home/fake/.kube/.kubeconfig", }, { - input: ":", + input: sep, want: "$HOME/.kube/config", }, { @@ -796,8 +811,10 @@ func TestGetKubeConfigPath(t *testing.T) { for _, test := range tests { t.Setenv(clientcmd.RecommendedConfigPathEnvVar, test.input) - if result := PathFromEnv(); result != os.ExpandEnv(test.want) { - t.Errorf("Expected first split chunk, got: %s", result) + result := PathFromEnv() + expandedWant := os.ExpandEnv(test.want) + if !equalPaths(result, expandedWant) { + t.Errorf("Expected first split chunk, got: %s (want %s)", result, expandedWant) } } }