Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions pkg/minikube/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is only for windows, add an if statemnet to only run in wondows

if up := os.Getenv("USERPROFILE"); up != "" {
_ = os.Setenv("HOME", up)
}
}

var tests = []struct {
input string
want string
Expand All @@ -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",
},
{
Expand All @@ -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)
}
}
}
Loading