forked from containers/common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request containers#633 from vrothberg/0.38-backports
[0.38] libimage: force remove: only untag on multi tag image
- Loading branch information
Showing
3 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package libimage | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/containers/common/pkg/config" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRemoveImages(t *testing.T) { | ||
// Note: this will resolve pull from the GCR registry (see | ||
// testdata/registries.conf). | ||
busyboxLatest := "docker.io/library/busybox:latest" | ||
|
||
runtime, cleanup := testNewRuntime(t) | ||
defer cleanup() | ||
ctx := context.Background() | ||
|
||
pullOptions := &PullOptions{} | ||
pullOptions.Writer = os.Stdout | ||
pulledImages, err := runtime.Pull(ctx, busyboxLatest, config.PullPolicyAlways, pullOptions) | ||
require.NoError(t, err) | ||
require.Len(t, pulledImages, 1) | ||
|
||
err = pulledImages[0].Tag("foobar") | ||
require.NoError(t, err) | ||
|
||
// containers/podman/issues/10685 - force removal on image with | ||
// multiple tags will only untag but not remove all tags including the | ||
// image. | ||
rmReports, rmErrors := runtime.RemoveImages(ctx, []string{"foobar"}, &RemoveImagesOptions{Force: true}) | ||
require.Nil(t, rmErrors) | ||
require.Len(t, rmReports, 1) | ||
require.Equal(t, pulledImages[0].ID(), rmReports[0].ID) | ||
require.False(t, rmReports[0].Removed) | ||
require.Equal(t, []string{"localhost/foobar:latest"}, rmReports[0].Untagged) | ||
|
||
// The busybox image is still present even if foobar was force removed. | ||
exists, err := runtime.Exists(busyboxLatest) | ||
require.NoError(t, err) | ||
require.True(t, exists) | ||
} |