Merge pull request #11160 from afbjorklund/profile-test-docker-mock

Mock the docker call when calling it from tests
pull/11003/head
Medya Ghazizadeh 2021-04-20 14:21:06 -07:00 committed by GitHub
commit 366fa7e272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -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)

View File

@ -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...)
}

View File

@ -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)