From dad476803719ae2e86c703981caef0462e25260c Mon Sep 17 00:00:00 2001 From: unclejack Date: Mon, 30 Jun 2014 22:42:09 +0300 Subject: [PATCH] integcli: add & use pullImageIfNotExist for pulls This speeds up the tag cli integration tests by about 20 seconds. Docker-DCO-1.1-Signed-off-by: Cristian Staretu (github: unclejack) --- integration-cli/docker_cli_tag_test.go | 22 +++++++--------------- integration-cli/docker_utils.go | 12 ++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/integration-cli/docker_cli_tag_test.go b/integration-cli/docker_cli_tag_test.go index ef51f64644..032927e221 100644 --- a/integration-cli/docker_cli_tag_test.go +++ b/integration-cli/docker_cli_tag_test.go @@ -8,16 +8,12 @@ import ( // tagging a named image in a new unprefixed repo should work func TestTagUnprefixedRepoByName(t *testing.T) { - pullCmd := exec.Command(dockerBinary, "pull", "busybox") - out, exitCode, err := runCommandWithOutput(pullCmd) - errorOut(err, t, fmt.Sprintf("%s %s", out, err)) - - if err != nil || exitCode != 0 { - t.Fatal("pulling the busybox image from the registry has failed") + if err := pullImageIfNotExist("busybox:latest"); err != nil { + t.Fatal("couldn't find the busybox:latest image locally and failed to pull it") } - tagCmd := exec.Command(dockerBinary, "tag", "busybox", "testfoobarbaz") - out, _, err = runCommandWithOutput(tagCmd) + tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "testfoobarbaz") + out, _, err := runCommandWithOutput(tagCmd) errorOut(err, t, fmt.Sprintf("%v %v", out, err)) deleteImages("testfoobarbaz") @@ -62,18 +58,14 @@ func TestTagInvalidUnprefixedRepo(t *testing.T) { // ensure we allow the use of valid tags func TestTagValidPrefixedRepo(t *testing.T) { - pullCmd := exec.Command(dockerBinary, "pull", "busybox") - out, exitCode, err := runCommandWithOutput(pullCmd) - errorOut(err, t, fmt.Sprintf("%s %s", out, err)) - - if err != nil || exitCode != 0 { - t.Fatal("pulling the busybox image from the registry has failed") + if err := pullImageIfNotExist("busybox:latest"); err != nil { + t.Fatal("couldn't find the busybox:latest image locally and failed to pull it") } validRepos := []string{"fooo/bar", "fooaa/test"} for _, repo := range validRepos { - tagCmd := exec.Command(dockerBinary, "tag", "busybox", repo) + tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", repo) _, _, err := runCommandWithOutput(tagCmd) if err != nil { t.Errorf("tag busybox %v should have worked: %s", repo, err) diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 22217e2f03..74576ba489 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -75,6 +75,18 @@ func imageExists(image string) error { return err } +func pullImageIfNotExist(image string) (err error) { + if err := imageExists(image); err != nil { + pullCmd := exec.Command(dockerBinary, "pull", image) + _, exitCode, err := runCommandWithOutput(pullCmd) + + if err != nil || exitCode != 0 { + err = fmt.Errorf("image '%s' wasn't found locally and it couldn't be pulled: %s", image, err) + } + } + return +} + func cmd(t *testing.T, args ...string) (string, int, error) { out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...)) errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))