This speeds up the tag cli integration tests by about 20 seconds.
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -8,16 +8,12 @@ import ( |
| 8 | 8 |
|
| 9 | 9 |
// tagging a named image in a new unprefixed repo should work |
| 10 | 10 |
func TestTagUnprefixedRepoByName(t *testing.T) {
|
| 11 |
- pullCmd := exec.Command(dockerBinary, "pull", "busybox") |
|
| 12 |
- out, exitCode, err := runCommandWithOutput(pullCmd) |
|
| 13 |
- errorOut(err, t, fmt.Sprintf("%s %s", out, err))
|
|
| 14 |
- |
|
| 15 |
- if err != nil || exitCode != 0 {
|
|
| 16 |
- t.Fatal("pulling the busybox image from the registry has failed")
|
|
| 11 |
+ if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
| 12 |
+ t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
| 17 | 13 |
} |
| 18 | 14 |
|
| 19 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox", "testfoobarbaz") |
|
| 20 |
- out, _, err = runCommandWithOutput(tagCmd) |
|
| 15 |
+ tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "testfoobarbaz") |
|
| 16 |
+ out, _, err := runCommandWithOutput(tagCmd) |
|
| 21 | 17 |
errorOut(err, t, fmt.Sprintf("%v %v", out, err))
|
| 22 | 18 |
|
| 23 | 19 |
deleteImages("testfoobarbaz")
|
| ... | ... |
@@ -62,18 +58,14 @@ func TestTagInvalidUnprefixedRepo(t *testing.T) {
|
| 62 | 62 |
|
| 63 | 63 |
// ensure we allow the use of valid tags |
| 64 | 64 |
func TestTagValidPrefixedRepo(t *testing.T) {
|
| 65 |
- pullCmd := exec.Command(dockerBinary, "pull", "busybox") |
|
| 66 |
- out, exitCode, err := runCommandWithOutput(pullCmd) |
|
| 67 |
- errorOut(err, t, fmt.Sprintf("%s %s", out, err))
|
|
| 68 |
- |
|
| 69 |
- if err != nil || exitCode != 0 {
|
|
| 70 |
- t.Fatal("pulling the busybox image from the registry has failed")
|
|
| 65 |
+ if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
| 66 |
+ t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
|
| 71 | 67 |
} |
| 72 | 68 |
|
| 73 | 69 |
validRepos := []string{"fooo/bar", "fooaa/test"}
|
| 74 | 70 |
|
| 75 | 71 |
for _, repo := range validRepos {
|
| 76 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox", repo) |
|
| 72 |
+ tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", repo) |
|
| 77 | 73 |
_, _, err := runCommandWithOutput(tagCmd) |
| 78 | 74 |
if err != nil {
|
| 79 | 75 |
t.Errorf("tag busybox %v should have worked: %s", repo, err)
|
| ... | ... |
@@ -75,6 +75,18 @@ func imageExists(image string) error {
|
| 75 | 75 |
return err |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
+func pullImageIfNotExist(image string) (err error) {
|
|
| 79 |
+ if err := imageExists(image); err != nil {
|
|
| 80 |
+ pullCmd := exec.Command(dockerBinary, "pull", image) |
|
| 81 |
+ _, exitCode, err := runCommandWithOutput(pullCmd) |
|
| 82 |
+ |
|
| 83 |
+ if err != nil || exitCode != 0 {
|
|
| 84 |
+ err = fmt.Errorf("image '%s' wasn't found locally and it couldn't be pulled: %s", image, err)
|
|
| 85 |
+ } |
|
| 86 |
+ } |
|
| 87 |
+ return |
|
| 88 |
+} |
|
| 89 |
+ |
|
| 78 | 90 |
func cmd(t *testing.T, args ...string) (string, int, error) {
|
| 79 | 91 |
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...)) |
| 80 | 92 |
errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
|