diff --git a/agent/dockerclient/dockerapi/docker_client_test.go b/agent/dockerclient/dockerapi/docker_client_test.go index a095f458a18..f94bb490be2 100644 --- a/agent/dockerclient/dockerapi/docker_client_test.go +++ b/agent/dockerclient/dockerapi/docker_client_test.go @@ -821,18 +821,11 @@ func TestListImages(t *testing.T) { ctx, cancel := context.WithCancel(context.TODO()) defer cancel() response := client.ListImages(ctx, dockerclient.ListImagesTimeout) - if response.Error != nil { - t.Error("Did not expect error") - } + assert.NoError(t, response.Error, "Did not expect error") imageIDs := response.ImageIDs - if len(imageIDs) != 1 { - t.Error("Unexpected number of images in list", len(imageIDs)) - } - - if imageIDs[0] != "id" { - t.Error("Unexpected image id in the list:", imageIDs[0]) - } + assert.EqualValues(t, len(imageIDs), 1, "Unexpected number of images in list") + assert.EqualValues(t, imageIDs[0], "id", "Unexpected id in list of images") } func TestListImagesTimeout(t *testing.T) { @@ -847,13 +840,11 @@ func TestListImagesTimeout(t *testing.T) { }).MaxTimes(1).Return(nil, errors.New("test error")) ctx, cancel := context.WithCancel(context.TODO()) defer cancel() + response := client.ListImages(ctx, xImageShortTimeout) - if response.Error == nil { - t.Error("Expected error for pull timeout") - } - if response.Error.(apierrors.NamedError).ErrorName() != "DockerTimeoutError" { - t.Error("Wrong error type") - } + assert.Error(t, response.Error, "Expected error for pull timeout") + assert.Equal(t, response.Error.(apierrors.NamedError).ErrorName(), "DockerTimeoutError", "Wrong error type") + wait.Done() } diff --git a/agent/engine/docker_image_manager.go b/agent/engine/docker_image_manager.go index b16b2e1584f..87d8c5fdd83 100644 --- a/agent/engine/docker_image_manager.go +++ b/agent/engine/docker_image_manager.go @@ -335,7 +335,11 @@ func (imageManager *dockerImageManager) removeNonECSContainers(ctx context.Conte } var nonECSContainerRemoveAvailableIDs []string for _, id := range nonECSContainersIDs { - response, _ := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout) + response, icErr := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout) + if icErr != nil { + seelog.Errorf("Error inspecting non-ECS container id: %s - %v", id, icErr) + continue + } finishedTime, _ := time.Parse(time.Now().String(), response.State.FinishedAt) @@ -393,7 +397,11 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context, var imageWithSizeList []ImageWithSize for _, imageName := range nonECSImageNamesRemoveEligible { - resp, _ := imageManager.client.InspectImage(imageName) + resp, iiErr := imageManager.client.InspectImage(imageName) + if iiErr != nil { + seelog.Errorf("Error inspecting non-ECS image name: %s - %v", imageName, iiErr) + continue + } imageWithSizeList = append(imageWithSizeList, ImageWithSize{imageName, resp.Size}) } // we want to sort images with size ascending @@ -402,9 +410,9 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context, }) // we will remove the remaining nonECSImages in each performPeriodicImageCleanup call() - var numImagesAlreadyDelete = 0 + var numImagesAlreadyDeleted = 0 for _, kv := range imageWithSizeList { - if numImagesAlreadyDelete == nonECSImagesNumToDelete { + if numImagesAlreadyDeleted == nonECSImagesNumToDelete { break } seelog.Infof("Removing non-ECS Image: %s", kv.ImageName) @@ -414,7 +422,7 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context, continue } else { seelog.Infof("Image removed: %s", kv.ImageName) - numImagesAlreadyDelete++ + numImagesAlreadyDeleted++ } } }