mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Protect images in the integration/ suite
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
package environment
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/integration-cli/fixtures/load"
|
||||
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
||||
)
|
||||
|
||||
type protectedElements struct {
|
||||
images map[string]struct{}
|
||||
}
|
||||
|
||||
// ProtectImage adds the specified image(s) to be protected in case of clean
|
||||
func (e *Execution) ProtectImage(t testingT, images ...string) {
|
||||
for _, image := range images {
|
||||
@@ -7,6 +18,31 @@ func (e *Execution) ProtectImage(t testingT, images ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
type protectedElements struct {
|
||||
images map[string]struct{}
|
||||
// ProtectImages protects existing images and on linux frozen images from being
|
||||
// cleaned up at the end of test runs
|
||||
func ProtectImages(t testingT, testEnv *Execution) {
|
||||
images := getExistingImages(t, testEnv)
|
||||
|
||||
if testEnv.DaemonPlatform() == "linux" {
|
||||
images = append(images, ensureFrozenImagesLinux(t, testEnv)...)
|
||||
}
|
||||
testEnv.ProtectImage(t, images...)
|
||||
}
|
||||
|
||||
func getExistingImages(t testingT, testEnv *Execution) []string {
|
||||
// TODO: use API instead of cli
|
||||
result := icmd.RunCommand(testEnv.dockerBinary, "images", "-f", "dangling=false", "--format", "{{.Repository}}:{{.Tag}}")
|
||||
result.Assert(t, icmd.Success)
|
||||
return strings.Split(strings.TrimSpace(result.Stdout()), "\n")
|
||||
}
|
||||
|
||||
func ensureFrozenImagesLinux(t testingT, testEnv *Execution) []string {
|
||||
images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
|
||||
err := load.FrozenImagesLinux(testEnv.DockerBinary(), images...)
|
||||
if err != nil {
|
||||
result := icmd.RunCommand(testEnv.DockerBinary(), "image", "ls")
|
||||
t.Logf(result.String())
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
return images
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user