diff --git a/cmd/minikube/cmd/delete_test.go b/cmd/minikube/cmd/delete_test.go index 825bd72caf..6c6a98939f 100644 --- a/cmd/minikube/cmd/delete_test.go +++ b/cmd/minikube/cmd/delete_test.go @@ -194,6 +194,9 @@ func TestDeleteAllProfiles(t *testing.T) { t.Errorf("got %d test machines, expected %d: %s", len(mFiles), numberOfTotalMachineDirs, mFiles) } + config.DockerContainers = func() ([]string, error) { + return []string{}, nil + } validProfiles, inValidProfiles, err := config.ListProfiles() if err != nil { t.Error(err) diff --git a/pkg/minikube/config/profile.go b/pkg/minikube/config/profile.go index 8cff826ae5..18de6a27ba 100644 --- a/pkg/minikube/config/profile.go +++ b/pkg/minikube/config/profile.go @@ -192,6 +192,11 @@ func DeleteProfile(profile string, miniHome ...string) error { return os.RemoveAll(ProfileFolderPath(profile, miniPath)) } +// DockerContainers lists all containers created by docker driver +var DockerContainers = func() ([]string, error) { + return oci.ListOwnedContainers(oci.Docker) +} + // ListProfiles returns all valid and invalid (if any) minikube profiles // invalidPs are the profiles that have a directory or config file but not usable // invalidPs would be suggested to be deleted @@ -203,7 +208,7 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile, return nil, nil, err } // try to get profiles list based on all containers created by docker driver - cs, err := oci.ListOwnedContainers(oci.Docker) + cs, err := DockerContainers() if err == nil { pDirs = append(pDirs, cs...) } diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go index c93ff7f2df..8c778bb393 100644 --- a/pkg/minikube/config/profile_test.go +++ b/pkg/minikube/config/profile_test.go @@ -52,8 +52,16 @@ func TestListProfiles(t *testing.T) { {2, "p5_partial_config", ""}, } + DockerContainers = func() ([]string, error) { + return []string{}, nil + } val, inv, err := ListProfiles(miniDir) + num := len(testCasesValidProfs) + len(testCasesInValidProfs) + if num != len(val)+len(inv) { + t.Errorf("ListProfiles length = %d, expected %d\nvalid: %v\ninvalid: %v\n", len(val)+len(inv), num, val, inv) + } + for _, tt := range testCasesValidProfs { if val[tt.index].Name != tt.expectName { t.Errorf("expected %s got %v", tt.expectName, val[tt.index].Name)