Mock the docker call when calling it from tests
parent
f9efad1bc5
commit
ef036e9297
|
@ -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)
|
||||
|
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue