Skip to content

Commit

Permalink
Merge pull request moby#42167 from cpuguy83/testPushMultipleTags
Browse files Browse the repository at this point in the history
  • Loading branch information
AkihiroSuda committed Mar 20, 2021
2 parents 788f288 + 601707a commit dc4a600
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration-cli/cli/cli.go
Expand Up @@ -26,6 +26,7 @@ type CmdOperator func(*icmd.Cmd) func()

// DockerCmd executes the specified docker command and expect a success
func DockerCmd(t testing.TB, args ...string) *icmd.Result {
t.Helper()
return Docker(Args(args...)).Assert(t, icmd.Success)
}

Expand Down
11 changes: 10 additions & 1 deletion integration-cli/docker_cli_push_test.go
Expand Up @@ -12,6 +12,7 @@ import (
"testing"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration-cli/cli/build"
"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
Expand Down Expand Up @@ -81,7 +82,15 @@ func testPushMultipleTags(c *testing.T) {
// tag the image and upload it to the private registry
dockerCmd(c, "tag", "busybox", repoTag1)
dockerCmd(c, "tag", "busybox", repoTag2)
dockerCmd(c, "push", repoName)

args := []string{"push"}
if versions.GreaterThanOrEqualTo(DockerCLIVersion(c), "20.10.0") {
// 20.10 CLI removed implicit push all tags and requires the "--all" flag
args = append(args, "--all-tags")
}
args = append(args, repoName)

dockerCmd(c, args...)

imageAlreadyExists := ": Image already exists"

Expand Down
1 change: 1 addition & 0 deletions integration-cli/docker_utils_test.go
Expand Up @@ -41,6 +41,7 @@ func dockerCmdWithError(args ...string) (string, int, error) {

// Deprecated: use cli.Docker or cli.DockerCmd
func dockerCmd(c testing.TB, args ...string) (string, int) {
c.Helper()
result := cli.DockerCmd(c, args...)
return result.Combined(), result.ExitCode
}
Expand Down
9 changes: 9 additions & 0 deletions integration-cli/requirements_test.go
Expand Up @@ -189,6 +189,15 @@ func TODOBuildkit() bool {
return os.Getenv("DOCKER_BUILDKIT") == ""
}

func DockerCLIVersion(t testing.TB) string {
out, _ := dockerCmd(t, "--version")
version := strings.Fields(out)
if len(version) < 3 {
t.Fatal("unknown version output", version)
}
return version[2]
}

// testRequires checks if the environment satisfies the requirements
// for the test to run or skips the tests.
func testRequires(t *testing.T, requirements ...requirement.Test) {
Expand Down

0 comments on commit dc4a600

Please sign in to comment.