Browse code

TestPushMultipleTags: Add support for 20.10 CLI

In 20.10 we no longer implicitly push all tags and require a
"--all-tags" flag, so add this to the test when the CLI is >= 20.10

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 601707a655071e4ab2d3c7ee3f7f868af1774321)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2021/03/19 03:36:00
Showing 4 changed files
... ...
@@ -26,6 +26,7 @@ type CmdOperator func(*icmd.Cmd) func()
26 26
 
27 27
 // DockerCmd executes the specified docker command and expect a success
28 28
 func DockerCmd(t testing.TB, args ...string) *icmd.Result {
29
+	t.Helper()
29 30
 	return Docker(Args(args...)).Assert(t, icmd.Success)
30 31
 }
31 32
 
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"testing"
13 13
 
14 14
 	"github.com/docker/distribution/reference"
15
+	"github.com/docker/docker/api/types/versions"
15 16
 	"github.com/docker/docker/integration-cli/cli/build"
16 17
 	"gotest.tools/v3/assert"
17 18
 	"gotest.tools/v3/icmd"
... ...
@@ -81,7 +82,15 @@ func testPushMultipleTags(c *testing.T) {
81 81
 	// tag the image and upload it to the private registry
82 82
 	dockerCmd(c, "tag", "busybox", repoTag1)
83 83
 	dockerCmd(c, "tag", "busybox", repoTag2)
84
-	dockerCmd(c, "push", repoName)
84
+
85
+	args := []string{"push"}
86
+	if versions.GreaterThanOrEqualTo(DockerCLIVersion(c), "20.10.0") {
87
+		// 20.10 CLI removed implicit push all tags and requires the "--all" flag
88
+		args = append(args, "--all-tags")
89
+	}
90
+	args = append(args, repoName)
91
+
92
+	dockerCmd(c, args...)
85 93
 
86 94
 	imageAlreadyExists := ": Image already exists"
87 95
 
... ...
@@ -41,6 +41,7 @@ func dockerCmdWithError(args ...string) (string, int, error) {
41 41
 
42 42
 // Deprecated: use cli.Docker or cli.DockerCmd
43 43
 func dockerCmd(c testing.TB, args ...string) (string, int) {
44
+	c.Helper()
44 45
 	result := cli.DockerCmd(c, args...)
45 46
 	return result.Combined(), result.ExitCode
46 47
 }
... ...
@@ -189,6 +189,15 @@ func TODOBuildkit() bool {
189 189
 	return os.Getenv("DOCKER_BUILDKIT") == ""
190 190
 }
191 191
 
192
+func DockerCLIVersion(t testing.TB) string {
193
+	out, _ := dockerCmd(t, "--version")
194
+	version := strings.Fields(out)
195
+	if len(version) < 3 {
196
+		t.Fatal("unknown version output", version)
197
+	}
198
+	return version[2]
199
+}
200
+
192 201
 // testRequires checks if the environment satisfies the requirements
193 202
 // for the test to run or skips the tests.
194 203
 func testRequires(t *testing.T, requirements ...requirement.Test) {